开发者

JavaScript/jQuery - How to detect if a page is embedded by others?

开发者 https://www.devze.com 2023-04-12 23:52 出处:网络
Say I have a page index.html, how can I detect, using JS or jQuery, if my page is embedded in other HTML page through a frame or an iframe?

Say I have a page index.html, how can I detect, using JS or jQuery, if my page is embedded in other HTML page through a frame or an iframe?

+----------------------+
|  Other people's site |
|   +------------+   开发者_JAVA技巧  |
|   | index.html |     |
|   | oops!      |     |
|   | embedded!  |     |
|   +------------+     |
|                      |
+----------------------+ 


if(window.top !== window.self) {
    // embedded
}

window.top is the top-level window. window.self is the window the script is executing in. If the current window is not the top-level window, it must be embedded.

0

精彩评论

暂无评论...
验证码 换一张
取 消