简体   繁体   中英

How to detect if Javascript is running in an cross-domain IFrame in Opera?

How to detect if JavaScript is running in an cross-domain IFrame in Opera? If I try to test if(typeof iframe.parent.document === 'undefined') Opera 12 just seems to give "Unhandled Error: Security error: attempted to read protected " which cannot be caught in code thus breaking execution.

You can't. However if your objective is to prevent someone on a different domain from embedding your page in an iframe, there is a http header you can send to prevent this.

https://developer.mozilla.org/en-US/docs/The_X-FRAME-OPTIONS_response_header

It's supported by most modern browsers. It allows you to specify which sites are allowed to embed your page in an iframe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM