开发者

Prevent drupal from loading other module's javascript

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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜