[thelist] Javascript popup & focus

Jason Handby jasonh at corestar.co.uk
Tue Dec 23 07:19:35 CST 2003

Hi Chris,

> I have a selection of pages in a website, and when they load they need to
> know if a javascript popup window has been launched. If it has,
> then focus
> needs to be given to the popup.
> I have something like this for creating the window:
> var win = window.open('foo.asp','bar','width=600,height=250');
> And then I was looking at something like:
> if (window.bar) {
> window.bar.focus();
> }
> This obviously doesn't work, but can I do somehting similar?

I've just had to do something similar, to deal with users running popup
blockers. (If they are then my popup window won't have been opened.) Try
something like this:

	var p = window.open('foo.asp', 'bar', 'width=600,height=250');

	if (p.constructor == window.constructor)
		// Popup window was opened


More information about the thelist mailing list