简体   繁体   English

在 js 中将“X-Frame-Options”设置为“sameorigin 错误”

[英]Catch set 'X-Frame-Options' to 'sameorigin error in js

I load some page in iframe.我在 iframe 中加载了一些页面。 I get the error我收到错误

Refused to display 'url' in a frame because it set 'X-Frame-Options' to 'sameorigin'.

How can I handle this type of error in javascript, and show my message for this case?我如何在 javascript 中处理这种类型的错误,并在这种情况下显示我的消息? window.onerror doesn't catch this error. window.onerror没有捕捉到这个错误。 Is there any possible way to do this?有没有可能的方法来做到这一点?

DOMException comes to help here. DOMException 在这里提供帮助。

I got a trick working as follows: [have not tested cross-browser!]我有一个技巧如下:[尚未测试跨浏览器!]

Define iframe's onload event handler defined as定义 iframe 的 onload 事件处理程序定义为

 $('#myIframe').on('load', function() { setTimeout(function() { try { console.log($('#myIframe')[0].contentWindow.document); } catch (e) { console.log(e); if (e.message.indexOf('Blocked a frame with origin') > -1 || e.message.indexOf('from accessing a cross-origin frame.') > -1) { alert('Same origin Iframe error found!!!'); //Do fallback handling if you want here } } }, 1000); });

暂无
暂无

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

相关问题 错误:在框架中,因为它将“X-Frame-Options”设置为“sameorigin” - Error : in a frame because it set 'X-Frame-Options' to 'sameorigin' 从“ X-Frame-Options”到“ SAMEORIGIN”。 错误 - 'X-Frame-Options' to 'SAMEORIGIN'. error 谷歌视图在框架中,因为它将'X-Frame-Options'设置为'SAMEORIGIN' - Google Views in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN' 拒绝显示在一个框架中,因为它将'X-Frame-Options'设置为'SAMEORIGIN' - Refused to display in a frame , because it set 'X-Frame-Options' to 'SAMEORIGIN' 拒绝显示,将X-Frame-Options设置为SAMEORIGIN - Refused to display, set X-Frame-Options to SAMEORIGIN X-Frame-Options:sameorigin的跨域错误? - Cross-origin error with X-Frame-Options:sameorigin? 捕获JavaScript中的X-Frame-Options错误 - Catch X-Frame-Options Error in javascript 得到错误拒绝在框架中显示“ http://www.asp.net/”,因为它使用iframe-resizer将“ X-Frame-Options”设置为“ SAMEORIGIN” - Getting the error Refused to display 'http://www.asp.net/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN' with iframe-resizer 拒绝在框架中显示“url”,因为它将“X-Frame-Options”设置为“sameorigin”。 嵌入谷歌 tresns 图 - Refused to display 'url' in a frame because it set 'X-Frame-Options' to 'sameorigin'. embed a google tresns graph 拒绝在框架中显示“http://vimeo.com/27577981”,因为它将“X-Frame-Options”设置为“SAMEORIGIN” - Refused to display 'http://vimeo.com/27577981' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM