如何防止下载并运行脚本?

发布于 2024-10-08 21:33:31 字数 410 浏览 0 评论 0原文

我想知道 JavaScript 中是否可以阻止 对象运行?

我需要让它就像它从未存在过一样。是否存在可以阻止执行脚本的事件(基于 src 参数)?

我的目标是 Internet Explorer 8,但也欢迎其他浏览器的解决方案(尽管它对我没有任何帮助;))。

并且请不要使用 JQuery 或其他库。我正在用 C++ 编写一个 IE 插件,但我可以使用 MSHTML 来“使用”JavaScript。

I wonder if it is possible in JavaScript to prevent <script src="unwantedscript.js" type="text/javascript"></script> object from running?

I need to make it like it never existed. Is there an event where I can prevent from executing a script (based on src argument)?

I'm targeting Internet Explorer 8 but solution for other browsers are also welcomed (though it won't help me in anything ;)).

And please no JQuery or other libraries. I'm writing in C++ an IE add-on but I can use interfaces from MSHTML to 'use' JavaScript.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟花肆意 2024-10-15 21:33:31

在 IE (MSHTML) 中,这很简单。您只需对 HTTP 请求进行 404 处理即可获取 unwantedscript.js

In IE (MSHTML) it's simple. You just 404 the HTTP request to get unwantedscript.js.

旧梦荧光笔 2024-10-15 21:33:31

试图阻止免费托管网站的广告?如果您这样做,您的网站可能会被托管公司删除,因此请小心。

除了将其包装在条件注释中之外,您实际上无能为力

<!--[if IE 5]>
    <script src="foo.js"></script>
<![endif]-->

,但如果将其注入到页面中,您可能无法包装它。

Trying to block a free hosting websites ads? If you do that your site can be deleted by the hosting company so watch out.

There is really nothing you can do about it other than wrap it in conditional comments

<!--[if IE 5]>
    <script src="foo.js"></script>
<![endif]-->

but if it is being injected into the page, you probably can not wrap it.

芯好空 2024-10-15 21:33:31

由于您(显然)无法为脚本注入 404 错误代码,因此还有另一个想法:使用 自定义安全提供程序并拒绝 .js URL。

Since you (apparently) cannot inject a 404 error code for scripts, here's another idea: Use a custom security provider and reject the .js URL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文