views:

91

answers:

1

I have a drupal page that I'm using in a way that's very different from all the other pages of the site.

I have a module that loads a set of specialized js on this page. I'm finding that my JS does not work well with the js from other modules or perhaps drupal core.

How can I prevent the other modules from doing drupal_add_js on that specific page.

Thanks!

+4  A: 

There is no way to prevent other modules from calling drupal_add_js() except for hacking those modules code.

For a 'one page exception', you could implement a myModule_preprocess_page() function and replace the content of $variables['script'] with your own script inclusion markup (you might need to check $variables['closure'] as well).

Alternatively, you could implement a specific version of page.tpl.php for that page and just replace the printing of the $scripts variable with your own output.

Note that while both workaround suggestions could be valid solutions for special circumstances, I would strongly suggest to check why your JavaScript 'does not work well with the js from other modules'. Conflicting JavaScript is quite often an indicator of a bug/sloppy code within one or more scripts, so your time might be better spent finding and fixing those than by implementing workarounds that are hard to maintain in the long run.

Henrik Opel
+1 A good solution and sound advise. The root of the problem might very well be custom js.
googletorp