0

the following is my js file mymodule.js

$(document).ready(function(){

    alert('test');
});

and i just add this file in my customtheme.info .

scripts[] = js/mymodule.js

However, the js code only be executed at some pages, not all pages.

What could the problem will be?

Does anyone have the same situation before?

Please help me fix this.

0

In Drupal 7 to avoid conflicts with another library you should wrap your code in:

(function ($) {
  // Original JavaScript code.
})(jQuery);

To learn more visit: http://drupal.org/update/modules/6/7#javascript_compatibility

| improve this answer | |
0

Try it by implementing hook_init() into your .module file:

function YOURMODULE_init() {
    drupal_add_js(drupal_get_path('module', 'YOURMODULE')  ."/YOURSCRIPT.js",  array('every_page' => TRUE));
}

Also make sure your module is in its proper place: sites/all/modules/YOURMODULE or a subfolder of this.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.