Safari 3 Popup Window Bug Fix

While working on a project today I found an interesting bug in Safari that prevents the normal javascript method of opening a popup window form working. Here is a concise work-around.

The Problem:

In the new version of Safari if you try to open a pop-up window and pass a URL to the new window via Javascript nothing happens!

This means that the very common piece of code below does not work:

window.open( "http://google.com", "google" );

The Solution:

As we had already used this code quite liberally throughout a project I had to come up with a work-around:

function popup( url, title, options )
	{
	var newWin = window.open( url, title, options );
	if( !newWin )
		{
		newWin = window.open('',title, options);
		newWin.location.href = url;
		}
	}

First we try to open a window in the normal way, then we check to see whether that window was actually created. If it wasn't then we open a new window without passing a URL to it. We then direct the window to the URL using the "window.location.href" property.

The code works perfectly and is fairly transparent.

Hope this helps!