Select Page

Opening Pop-up windows from Flash

Recently I read that the best way to open pop-up windows from Flash was to use the ExternalInterface class. I found some code that looked good but it didn’t work in Safari on a Mac.

if (ExternalInterface.available) {
	ExternalInterface.call("window.open",
				"popup.html",
				"win",
				"height=300,
				width=400,
				toolbar=no,
				scrollbars=yes");
} else {
	getURL('popup.html', '_blank');
}

However it isn’t that hard to just use getURL and call a javascript function set in the html page:

//javascript
	function openPopup() {
		winWidth = 450;
		winHeight = 680;
		screenWidth = screen.availWidth;
		screenHeight = screen.availHeight;
		if (screenWidth < winWidth) {
			winWidth = screenWidth;
		}
		if (screenHeight < winHeight) {
			winHeight = screenHeight;
		}
		winTop = (screenHeight - winHeight) / 2;
		winLeft = (screenWidth - winWidth) / 2;
		window.open(\'page.html\',\'Title\',\'width=450,
				height=680,scrollbars=no,
				status=no,resizeable=yes\'+ \',
				left=\' + winLeft + \',
				top=\' + winTop);
		//window.focus();
	}

So far this works in all browsers.