javascript 如何在 iframe 中禁用脚本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3839891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I disable scripts in my iframe?
提问by sange
I have an iframe that loads a page that I would like to disable the javascripts loading in the iframe loaded page. The loaded page has menu bars, dropdowns, etc. that make the home page that I am loading this iframe from load slow. Is there a way to disable javascript from my iframe page?
我有一个加载页面的 iframe,我想在 iframe 加载的页面中禁用 javascripts 加载。加载的页面有菜单栏、下拉菜单等,这使得我正在加载这个 iframe 的主页加载速度变慢。有没有办法从我的 iframe 页面禁用 javascript?
I need the javascripts to remain in the page because the visitor can visit the page.
我需要将 javascripts 保留在页面中,因为访问者可以访问该页面。
Here is my code for loading the iframe:
这是我加载 iframe 的代码:
<div style="position:absolute; overflow:hidden; width: 800; height:400; left:-170px; top:0px;">
<iframe src="/News/Pages/Default.aspx" style="overflow:hidden; width:100%; height:650;"
frameborder="0" marginheight="0" marginwidth="0" scrolling="no">
</iframe></div>
If this is not possible, than is there a way to stop/disable the iframe page from loading the .js files. The iframe page loads .js files, no javascript is inline.
如果这是不可能的,那么有没有办法停止/禁用 iframe 页面加载 .js 文件。iframe 页面加载 .js 文件,没有内联 javascript。
采纳答案by Chaoley
Check out the last code example on this page, http://www.iframehtml.com/iframe-scripts.html
查看此页面上的最后一个代码示例,http://www.iframehtml.com/iframe-scripts.html
Shows a method of stripping JavaScript from the iframe's source file using PHP
展示了一种使用 PHP 从 iframe 的源文件中剥离 JavaScript 的方法
回答by Sachin Shanbhag
As far as I am aware, I dont think you can disable loading of javascripts in the Iframe. Best way is, avoid script tags in the iframe page.
据我所知,我认为您不能在 Iframe 中禁用 javascripts 的加载。最好的方法是,避免 iframe 页面中的脚本标签。

