views:

768

answers:

3

Situation: you've got a .swf embedded in an html page, and when you click on something in the .swf, it needs to popup a chromeless window. Normally this would be fairly easy - but consider Safari, which completely disables all 'window.open' functionality while its popup-blocker is enabled (it makes an exception if the function is triggered onclick, but it doesn't count clicks in flash). How can you create something which gracefully degrades (provides an alternate and roughly equivalent experience) for browsers that won't execute window.open?

(note: this is AS3, and Safari 3 for PC or Mac we're talking about - but more broadly, any browser that doesn't support or refuses to allow the javascript window.open function.)

A: 

If your SWF is loaded using wmode='opaque' or wmode='transparent', then you could have the SWF output JavaScript code that would create an empty <div> that's positioned over the SWF area. That <div> could then handle the onclick event and create the popup window rather than the Flash code.

Ben Combee
Whoa. That's gutsy. I like that. You'd have to do some fancy scripting to make sure the div appeared in the right place at the right time, but it sounds like a good solution.
matt lohkamp
shit, I guess that you win by default. sucks that there isn't any better way.
matt lohkamp
A: 

is there anyway to generate a clickable html that loads the window?

Ape-inago
not sure what you mean exactly - but you can use javascript to insert whatever html onto the page that you want, and give it whatever behavior you want, and further more you can use ExternalInterface to interact with that javascript from the flash .swf, so chances are the answer is 'yes'.
matt lohkamp
A: 

...I figured it out myself (the div overlay seemed too crazy for the project I'm working on) - check out code.google.com/p/popupfromflash for the code I came up with.

It attempts to use ExternalInterface to setup a window.open function, and if that fails (particularly in Safari) it calls back into flash and prompts it to do a navigateToURL to pop up the window normally (instead of chromlessly)

matt lohkamp