最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - in drupal 7, how to add drupal_add_js in the module? - Stack Overflow

programmeradmin3浏览0评论

I made a module and wish to add js file to that module, I enable the module and obvious it works. But I didn't see the js file that module should take with.

I just put the code in the hook_menu() like this

function my2form_menu() {
      drupal_add_js(drupal_get_path('module', 'my2form') . '/abc.js');
}

is it ok?

I made a module and wish to add js file to that module, I enable the module and obvious it works. But I didn't see the js file that module should take with.

I just put the code in the hook_menu() like this

function my2form_menu() {
      drupal_add_js(drupal_get_path('module', 'my2form') . '/abc.js');
}

is it ok?

Share Improve this question asked May 19, 2012 at 17:58 user824624user824624 8,05035 gold badges120 silver badges210 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

If you plan to always include this JS file, you should add it in the .info file of your module: http://drupal/node/542202#scripts

And thus you can delete your hook_menu.

try another hook, called: modulename_js_alter()

works fpr my porposes.

发布评论

评论列表(0)

  1. 暂无评论