Safari blocking popups from Flash – fix
by Scott King on Oct.02, 2009, under ActionScript, JavaScript
I dont understand why Apple can make the best hardware in the world, and then proceed to create the worst software to put on it. Safari (like iTunes) is full of bugs, one of the most obivously yet most poorly documented is the problem that causes Safari to block pop-up windows from Flash even after a user has clicked to intiate the popup.
Here’s the fix:
ActionScript:
import flash.net.*;
...
mybutton.addEventListener(MouseEvent.CLICK, openPopup);
function openPopup(event:Event) {
var jsPopFunc:String = "popupWin";
var _winURL:String = "http://www.rivastakeout.com/staging/stake-your-claim/form.php";
var _winTarget:String = "_self";
var _winWidth:Integer = 600;
var _winHeight:Integer = 400;
var _winName:String = "popup";
var _winParams:String = "location=0,status=0,scrollbars=1";;
var result:Boolean;
if (ExternalInterface.available) {
result=Boolean(ExternalInterface.call(jsPopFunc , _winURL, _winTarget, _winWidth, _winHeight, _winName, _winParams));
}
if (!result) {
var request:URLRequest=new URLRequest(_winURL);
try {
navigateToURL(request, _popupWin);
} catch (e:Error) {
trace("Error occurred!");
}
}
}
JavaScript:
function popupWin(winURL, width, height, name, params){
var left = Math.floor((screen.width - width)/2);
var top = Math.floor((screen.height - height)/2);
var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
if(!name){
name = "newWin";
}
if(!params){
params = "location=0,status=0,scrollbars=0";
}
if (params){
winParms += "," + params;
}
var newWin = window.open(winURL, name, winParms);
if (newWin) {
return true;
}
else{
return false;
}
}
Further reading:
http://www.ultrashock.com/forums/actionscript/popups-from-flash-solution-92036.html
Leave a Reply
You must be logged in to post a comment.







October 14th, 2009 on 1:54 pm
Another Solution:::
/**
* Flash AS3 Page Change Utility
* @author Jordan Ambra
* @version 1.2
* http://www.zorked.com
* http://www.zorked.com/flash/flash-and-navigatetourl-popup-blocking/
*/
package com.zorked {
import flash.external.ExternalInterface;
import flash.net.*;
public class URLNavigator {
/**
* Utility function to wrap up changing pages. Avoids over-aggressive popup blockers.
* @param url The URL to change to. Either a String or a URLRequest
* @param window The target browser window/tab, generally _self, _top, or _blank
* @usage URLNavigator.ChangePage(“http://www.google.com”, “_blank”);
*/
public static function ChangePage(url:*, window:String = “_self”):void {
var req:URLRequest = url is String ? new URLRequest(url) : url;
if (!ExternalInterface.available) {
navigateToURL(req, window);
} else {
var strUserAgent:String = String(ExternalInterface.call(“function() {return navigator.userAgent;}”)).toLowerCase();
if (strUserAgent.indexOf(“firefox”) != -1 || (strUserAgent.indexOf(“msie”) != -1 && uint(strUserAgent.substr(strUserAgent.indexOf(“msie”) + 5, 3)) >= 7)) {
ExternalInterface.call(“window.open”, req.url, window);
} else {
navigateToURL(req, window);
}
}
}
}
}