简体   繁体   English

是否可以阻止在某些站点页面上加载.js文件来停止浏览器错误?

[英]Can I prevent a .js file from loading on certain site pages to stop browser errors?

I am getting a heavy load of errors because a Jquery .js file I have embedded in the Joomla index.php page. 我收到大量错误,因为我已经在Joomla index.php页面中嵌入了一个Jquery .js文件。 These errors are just browser errors but if I do any scrolling they just pile up. 这些错误只是浏览器错误,但是如果我进行任何滚动操作,它们就会堆积起来。

The specific error says this: 具体错误是这样的:

Uncaught TypeError: Cannot read property 'top' of null js-snippets.min.js:11
(anonymous function) js-snippets.min.js:11
f.event.dispatch js-snippets.min.js:4
h.handle.i js-snippets.min.js:4 

The page it is supposed to work on is fine and does not see this error. 它应该工作的页面很好,并且没有看到此错误。

I guess I could put the .js file reference in each html page that I need it for but I hate doing that. 我想我可以将.js文件引用放在需要的每个html页面中,但我讨厌这样做。 Isn't it better for the file to be in one single place? 将文件放在一个地方不是更好吗?

In any event if I could prevent the .js file from loading on page(s) it would be ideal. 无论如何,如果我可以阻止.js文件在页面上加载,那将是理想的选择。

Here is a link to the site in questions. 这是有问题的网站链接。

You could write a small script to test whether your js is needed and inject it only if needed. 您可以编写一个小脚本来测试是否需要您的js,并仅在需要时注入它。 Or better: adapt the .js so it tests by itself whether it is needed. 或更好:修改.js,以便它自己测试是否需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM