最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

dom - What does comparing `self` to `top` do in JavaScript? - Stack Overflow

programmeradmin0浏览0评论
if (self != top) {
  window.open(self.location,'_top');
}

What does self != top and window.open(self.location, '_top'); mean respectively?

if (self != top) {
  window.open(self.location,'_top');
}

What does self != top and window.open(self.location, '_top'); mean respectively?

Share Improve this question edited Nov 12, 2024 at 12:41 dumbass 27.3k4 gold badges37 silver badges74 bronze badges asked Nov 23, 2009 at 13:43 MaskMask 34.2k48 gold badges106 silver badges127 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

This will break out of a HTML frame and replace the top-level frame by the current page.

It's akin to clicking a link with target="_top" set which will throw away the plete frameset and replace it with the page that link points to. It's exactly what that code does by simply "opening a link" (in user terms; in JavaScript it takes the form of window.open) to the very same page we're seeing, but at the top level.

self in this respect is the page we're currently in. top is the top-level frame the browser is displaying. If the browser doesn't display a frameset, then self == top holds. If however, our page is framed, then they will be different.

So self != top detects if the page is displayed in a frame and window.open is, as noted before, just like clicking on a link with the target attribute set to "_top" (the second argument.

The old frame buster. Be also afraid of the frame buster buster.

It means "if I am loaded in a frame, i.e. not the top page, open a new window showing me"

发布评论

评论列表(0)

  1. 暂无评论