AS3: Pop-up blocker workaround


/ Published in: ActionScript 3
Save to your folder(s)

If pop-up blockers are making things difficult for you, try this awesome class. It uses Javascript to pop open a window if navigateToURL() fails.


Copy this code and paste it in your HTML
  1. /**
  2. * Flash AS3 Page Change Utility
  3. * @author Jordan Ambra
  4. * @version 1.2
  5. * http://www.zorked.com
  6. * http://www.zorked.com/flash/flash-and-navigatetourl-popup-blocking/
  7. */
  8.  
  9. package com.zorked {
  10. import flash.external.ExternalInterface;
  11. import flash.net.*;
  12.  
  13. public class URLNavigator {
  14.  
  15. /**
  16. * Utility function to wrap up changing pages. Avoids over-aggressive popup blockers.
  17. * @param url The URL to change to. Either a String or a URLRequest
  18. * @param window The target browser window/tab, generally _self, _top, or _blank
  19. * @usage URLNavigator.ChangePage("http://www.google.com", "_blank");
  20. */
  21. public static function ChangePage(url:*, window:String = "_self"):void {
  22. var req:URLRequest = url is String ? new URLRequest(url) : url;
  23. if (!ExternalInterface.available) {
  24. navigateToURL(req, window);
  25. } else {
  26. var strUserAgent:String = String(ExternalInterface.call("function() {return navigator.userAgent;}")).toLowerCase();
  27. if (strUserAgent.indexOf("firefox") != -1 || (strUserAgent.indexOf("msie") != -1 && uint(strUserAgent.substr(strUserAgent.indexOf("msie") + 5, 3)) >= 7)) {
  28. ExternalInterface.call("window.open", req.url, window);
  29. } else {
  30. navigateToURL(req, window);
  31. }
  32. }
  33. }
  34.  
  35. }
  36.  
  37. }

URL: http://www.zorked.com/flash/flash-and-navigatetourl-popup-blocking/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.