0

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.........

Community
  • 1
  • 1
user254582
  • 121
  • 1
  • 3
  • 12
  • Why not put your information on the page being viewed, where it belongs? – Carl Smotricz Apr 26 '10 at 06:29
  • @Carl: look at the history; OP has ignored this advice several times and seems dead set on implementing the ghastly user-hostile solution that everyone hates. It even appears to be for a login form, which makes the idea of opening with disabled browser chrome even more hilariously inappropriate. – bobince Apr 26 '10 at 09:31
  • @bobince: Yep, agree completely. I tend to react with hostility to SEO questions ("how can I game the system without getting caught?"), and this is an even more obscene violation of users' wishes. I hope this guy's company goes belly up. – Carl Smotricz Apr 26 '10 at 11:58

3 Answers3

4

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.

Ben Blank
  • 54,908
  • 28
  • 127
  • 156
1

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

naivists
  • 32,681
  • 5
  • 61
  • 85
-1

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');

Tim
  • 6,986
  • 8
  • 38
  • 57