Home > Web Front-end > JS Tutorial > body text

禁止iframe页面的所有js脚本如alert及弹出窗口等_javascript技巧

WBOY
Release: 2016-05-16 16:37:34
Original
1181 people have browsed it

今天做一个小软件遇到一个问题,就是在一个页面里面需要放一个iframe框架来预览网站,可是被预览的这个网站中含有很多js脚本,如弹出窗口,提示框,最可恶的是一直让设为首页和加入收藏,我想应该有办法禁止iframe里面的脚本吧,于是百度了一下,还发现不少新大陆,于是解决了这个问题,记录下来,方便以后查询,也方便大家参考:

<iframe src="fillseo.html"></iframe>
Copy after login

fillseo.html里面有个js脚本,其中有alert,还有弹出窗口,很可恶吧,如何禁止掉它们?
而且这个fillseo.html是不同的域的文件。

经过查阅无数相关资料,发现下面的代码,完全可以解决这个问题:

程序代码一:

<noscript><iframe src=fillseo.html></iframe></noscript>
Copy after login

或者

程序代码二:

<iframe src="fillseo.htm" width="200" height="200" id="Pcyear"></iframe>
<script>
var fillseo_window=window.frames["Pcyear"];
fillseo_window.window.alert=function(){
alert("弹弹弹!");
//也可以写你想写的东东
};
</script>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!