开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜