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

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

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"

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742377797a4432539.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信