Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
387 views
in Technique[技术] by (71.8m points)

javascript - Detect Blocked popups without opening a popup

This question has been raised many times on "How to check if the popup is blocked on my browser or not" and all the solutions that i found have proposed a solution where a new popup window is opened for testing.

References:

  1. "Detect blocked popup in Chrome"

  2. "How can I detect if a browser is blocking a popup?"

etc.

I would like to know if there is any possibility of knowing a blocked popup, without actually opening one.

Because due to many reasons the test pop up may take time to close, which looks ugly on start-page of your application.

For example if we could use anything from the request header from the client, to know the popup preferences etc like we can get for the language preferences.

It'll be a huge help. Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As far as I know, popup blockers works by overwrite a window.open function and in most cases return a null. So one way is to detect if window.open is still nativ function.

You can test that with toString method, which return [native code] as a body of that function. toString not work in old IE, so instead of that use ''+ to convert function.

var havePopupBlockers = ('' + window.open).indexOf('[native code]') === -1;

This is not silver bullet, but can detect potential risk. I test this on Chrome, FF, IE8 and IE9 with some various popup blockers and works.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...