开发者

What's the difference between New Blank Window and Popup in Javascript terms

Hello again StackOverflow Community:

I need to prevent my site from being opened in traditional popup windows (due to some fraud prevention issues, since the site is an ad network and fraud can be carried by automatically loading ads within popup windows). By popup windows I mean the small floating ones opened like: window.open(URL, name, options). At first I was checking for the window.opener property, like:

if (window.opener !== null && window.opener !== undefined) {

window.self.close();

}

But that obviously also closes a normal blank window (from target='_blank') and thus the site cannot be shared in Facebook or Twitter where an external link is loaded in a blank window. Is there a way to know when a new window specifically was a popup window. I was thinking of doing the code above but checking for properties commonly disabled in popups, like toolbars, statusbar, etc. Example:

if (window.toolbar.visible !== true && other window properties 开发者_如何转开发are checked) {

window.self.close();

}

Is this approach right? What other ideas can be used? Thanks a lot for your time.


Kind of a fool's errand if you ask me.

  • Impossible to weed out false-positives
  • Most browsers won't obey window.close() if the opener is from a different domain
  • Would fail if javascript was disabled
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜