Hi

for some reason my script wont detect the opener window when the page is launched target blank from flash, but detects it fine when its launched from target blank html. of course this problem only exists in ie6 and 7. Does anyone have a fix, should I pass a variable from flash? thanks.

Dani AI

Generated

As described, IE6/7 will sometimes return a null window.opener when a new window is opened directly from a Flash movie (target="_blank"). That makes the opener-check approach unreliable in those browsers. The practical, proven workaround is to have the containing HTML page open the new window with JavaScript (called from Flash). That way the browser creates a proper DOM opener reference.

Add a small JS wrapper in the page that embeds the SWF, and allow scripting from Flash. Example embedding bits and a safe opener helper:

<object ...>
  <param name="movie" value="your.swf" />
  <param name="allowScriptAccess" value="always" />
  <embed src="your.swf" allowScriptAccess="always"></embed>
</object>

<script>
function openFromFlash(url, name) {
  var winName = name || ('fromFlash_' + +new Date());
  var w = window.open('', winName);
  w.location = url;
  try { w.focus(); } catch(e) {}
}
</script>

From Flash use ExternalInterface to call that function (fallback to navigateToURL/getURL if ExternalInterface is not available). A small ActionScript example:

// AS3
import flash.external.ExternalInterface;
if (ExternalInterface.available) {
  ExternalInterface.call("openFromFlash", "http://example.com", "fromFlashWindow");
} else {
  navigateToURL(new URLRequest("http://example.com"), "_blank");
}

Notes and troubleshooting: set allowScriptAccess so JS/Flash can talk; if you cannot change the SWF, consider adding a query parameter (e.g. ?from=flash) so the opened page can adapt; be aware of popup blockers (the call should be triggered by a user action); and remember cross-origin rules: you can set opener.location to redirect another window, but you cannot read cross-domain DOM properties. This approach is the most reliable fix for the IE6/7 behavior mentioned by and requested by .

Recommended Answers

All 2 Replies

Hi cmills83,

Please show your code.

first page is just has a target blank link in the flash then the page that is opened has:

function swapWin(winLink) {
	if (window.opener != null && !window.opener.closed) {
		window.opener.location = winLink;
		window.opener.focus();
		}
	else {
		window.open(winLink, "newWindow");
	}
}

and called with

<a href="javascript:swapWin('http://www.google.com/');">link to brand site</a>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.