Possible Duplicate:
How can I detect if a browser is blocking a popup?
hi iam trying to open a child window with disabled toolbar.......
how to check whether the child window is opened or not and then display this alert??
can someone help with code.........
When you create a new window using window.open()
, it returns a handle to the (theoretically) opened window. You can then test that handle to determine whether the window is open:
var child = window.open("mypopup.html");
// some popup blockers prevent the window from being created (!child) and
// others just close them before they're displayed (child.closed)
if (!child || child.closed) {
// tell the user to turn off their popup blocker
}
Popups are very intrusive, however, and you should consider trying to display the "popup" information within the page. In particular, have a look at "dialog" scripts. If you're using jQuery, a very nice Dialog widget is included in the jQuery UI library.
I think, if popups are blocked, window.open()
will return a null
, not a window object. You can read it in an MSDN article:
If you are not sure whether a pop-up window is blocked, check your functions that return a window object. You can tell if a pop-up window has been blocked if these functions return null. In particular, you need to check the value of window.open to avoid script errors when your pop-up windows are blocked.
Also, this will give you some hints about detection of popup blockers: http://www.visitor-stats.com/articles/detect-popup-blocker.php
You need to give us the Javascript you are using so that we can help. You will need an 'if' statement.
Display alerts like this in javascript:
alert('Please turn off your pop-up blocker');
精彩评论