今天我爱模版在做一个客户的网站时,需要引用另一个网站的内容。第一个想到的是iframe。当我用iframe引用时,发现,打开之后总是跳转到引用网站上。我想可能该网站禁止别人的引用。查看源代码,发现了下面这段js:
<script type="text/javascript"> if(self != top) top.location.replace(self.location); </script>
本地测试了下,把这段代码注释了,就可以引用了。
下面是从网上摘抄来的,js禁止iframe引用的几种方法:
方法一:
<script language="javascript"> if( top.location != self.location) top.location.href=self.location.href; </script>方法二:
<script language="javascript"> if (top.location != location) top.location.href = location.href; </script>方法三:
<script language="javascript"> if (top.location != self.location) {top.location=self.location;} </script>方法四:
<script language="javascript"> if (top.frames.length!=0) top.location=self.document.location; </script>上面四种方法,可以简单的破解:
<iframe src="你的页面地址" name="tv" marginwidth="0" marginheight="0" scrolling="No" noResize frameborder="0" id="tv" framespacing="0" width="580" height="550" VSPACE=-145 HSPACE=-385></iframe> <script language="javascript"> var location=""; var navigate=""; frames[0].location.href=""; </script>下面这种方法可以彻底解决被iframe引用:
<script language="javascript"> if(top != self){ location.href = "about:blank"; } </script>