简体   繁体   English

如果我的应用程序正在由iframe加载-我可以检测到它吗?

[英]If my app is being loaded by iframe - can I detect it?

I didn't find the information about this topic in google. 我在Google中找不到有关此主题的信息。 Can I detect if my (Rails) application is being loaded from iframe? 我可以检测是否从iframe加载了我的(Rails)应用程序吗? If yes, can I obtain the url of the iframe? 如果是,我可以获取iframe的网址吗? I'd like to do it by both javascript and on the server if it's not possible, if not - whatever way is easier. 我想通过javascript和在服务器上同时执行此操作(如果无法执行)-无论哪种方式都更容易。

through javascript its very easy. 通过javascript它非常容易。

function isInIframe () {
    try {
        return window.self !== window.top;
    } catch (e) {
        return true;
    }
}

server side , check http referer header. 服务器端,检查http Referer标头。

$_SERVER['HTTP_REFERER'] but this is not foolproof.

more 更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检测 iframe 是否已加载? - How can I detect whether an iframe is loaded? $没有定义-但是我可以看到它正在并且正在被加载 - $ is not defined - But i can see that it is and is being loaded 如何将内联样式添加到WPF WebBrowser中加载的文档中? - How can I inject inline styling into a Document being loaded in my WPF WebBrowser? 如何检查 iframe 是否已加载? 以及如何与 iframe 中的元素进行交互? - How can I check if an iframe is loaded or not? And how can I interact with the elements within the iframe? 如何防止我的网站页面被加载到其他网站的 iframe 中? - How to prevent my site page from being loaded into other website iframe? 如何检测iFrame何时全屏显示? - How can I detect when an iFrame goes fullscreen? 如何在HTML iFrame中检测滚动条的存在(使用Javascript)? - How can I detect a Scrollbar presence ( using Javascript ) in HTML iFrame? 是否可以检测到跨域iframe包含404响应? - Can I detect that a cross-domain iframe contains a 404 response? 如何检测iframe的来源何时更改? - How can I detect when source of iframe is changed? 我可以直接导航到iframe的本地内容,但仍加载到iframe中吗? 加上书签? - can i navigate to iframe's local content directly, but still loaded into iframe? bookmark it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM