Foolproof way to detect if this page is INSIDE a cross-domain iframe

后端 未结 8 1083
梦如初夏
梦如初夏 2020-12-05 13:37

An answer to \"Foolproof way to detect if iframe is cross domain\" describes a method to test if an iframe on a page points to a same-domain or cross-domain page, working ar

8条回答
  •  失恋的感觉
    2020-12-05 14:03

    With your current restrictions, there's no way to achieve this using the DOM API. Any evaluation with a window that belongs to another domain will spew out an error.

    However, a "hack" would be to send an XHR from your child window to load a known page in your domain. If this XHR completes successfully, then you know that both windows are the same domain.

    However, this will log an error message to the console.

提交回复
热议问题