[英]html page with and iframe inside loaded via ajax is refreshing whole site
[英]Redirect page when site is loaded from inside an Iframe?
我遇到的情况是,我创建了一个网站,该网站的客户不希望其他开发人员能够使用iframe,但是当有人使用iframe时,它会将用户重定向到该iframe试图通过的网站。
我一直在研究使我能够检测客户端网站是否加载到iframe中并将其重定向回该网站的代码。 作为JS领域的新手,我不确定100%如何做到这一点。
到目前为止,我已经将重定向代码放置在document.ready函数中
var url = "http://google.com";
$(location).attr('href',url);
因此,现在出现的问题是通过检测另一个开发人员在另一个站点的iframe中使用我的站点来利用重定向。
提前致谢!
要从iframe中退出,您可以执行以下操作:
// if the location of the top (topmost browser window) not equal to the current location then it redirects to the URL of the current window (iframe)
if (window.top.location != document.location) {
window.top.location.href = document.location.href;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.