3

我以前没有为 Drupal 开发过任何模块,我想我真的只是想验证一下这是否“正确”,我希望有人能提供帮助。它是为 Drupal 7 开发的,用于将 javascript 文件注入页面的页脚

sessioncam.module 文件:

<?php
/**
* @file
* The code below adds the sessioncam.js file in the footer section of your site
*/
?>

<?php
drupal_add_js(drupal_get_path('module', 'sessioncam') .'/sessioncam.js', array('type' => 'external', 'scope' => 'footer')) ;
?>

sessioncam.info 文件:

name = SessionCam
description = Module to inject the SessionCam recorder code
core = 7.x

任何帮助表示赞赏

4

1 回答 1

6

不太对。调用drupal_add_js()不应在全局范围内,而应在挂钩函数中。如果您希望在每个页面上添加它hook_init()是合适的:

function sessioncam_init() {
  drupal_add_js(drupal_get_path('module', 'sessioncam') .'/sessioncam.js', array('type' => 'external', 'scope' => 'footer')) ;
}
于 2013-06-06T20:01:02.760 回答