« Detecting Popups enabled for a Flash site»

Ever visited a Flash site and you're creating some amazing hooza watzit and at the end to proceed there's a HTML popup and you haven't enabled it for that domain yet :(. Wouldn't it be better to tell the user up front so they can enable it and not cry in frustration at the end.

Well - I came up with a solution that's a combination of the Actionscript ExternalInterface class and some simple Javascript. Simply use the following Javascript and Actionscript and in Flash you can detect and alert the user to enable popups before proceeding.

Use the following Javascript

JAVASCRIPT:
  1. <script language="JavaScript">
  2. var allowPopup = false
  3. var checkId;
  4. var popup;
  5. function checkPopup(){
  6.     popup = window.open('about:blank','','width=1,height=1,top=0,left=0,screenX=0,screenY=0,scrollbars=no');
  7.     clearInterval(checkId);
  8.     checkId = setInterval(function(){
  9.         clearInterval(checkId);
  10.         try {
  11.             popup.close();
  12.             allowPopup = true;
  13.         } catch(error) {
  14.             allowPopup = false;
  15.         }      
  16.     }, 250);
  17. }
  18. function getAllowPopup(){
  19.     return allowPopup;
  20. }
  21. window.onload = checkPopup;
  22. </script>

With the following Actionscript to get the 'allowPopup' Javascript variable to know whether HTML popups are enabled or not.

Actionscript:
  1. import flash.external.*;
  2. allowPop = ExternalInterface.call("getAllowPopup");

Download the above here or view the online example.