如何理解页面是否作为iframe(外部网站)使用javascript加载? [英] How to understand if page is loaded as iframe (external site) using javascript?

查看:305
本文介绍了如何理解页面是否作为iframe(外部网站)使用javascript加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试找到一个可靠的解决方案,以确定我的网页是否使用javascript在外部网站的iframe中加载。

I'm trying to find a reliable solution to determine if my page was loaded in iframe on external site using javascript.

如果iframe src位于同一个域它的preaty容易:你可以使用if(window.frameElement)或if(window.location!== window.parent.location),但如果iframe src不在同一个域上所有现代浏览器在访问父,甚至比较它时抛出异常为空。

If iframe src located on the same domain it's preaty easy: you can use if (window.frameElement) or if (window.location !== window.parent.location) but if iframe src is not on the same domain all modern browsers throw exception when accessing parent and even comparing it with null.

我完全失去了。

推荐答案

可能对编码恐怖条目感兴趣:我们完成了框架。提供关于此主题的有趣的技术讨论,包括解决方案和框架破坏。

You might be interested in the Coding Horror entry: We Done Been Framed. Offers an interesting technical discussion on this topic, including solutions, and frame-busting-busting.

这篇关于如何理解页面是否作为iframe(外部网站)使用javascript加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆