13 Replies Latest reply on Jun 26, 2007 7:30 AM by kglad

    JavaScript popup code not working 4 me

    essaeyu
      Hi,

      I am to trying to open pop windows in Flash through JavaScript. Now I found a number of ways to do this on the forums but none is working for me. When I click the swf button containing the pop code (embedded in html), nothing happens. I do not have pop windows blocked, and when I click the button in stand alone swf file (i.e. not embedded in html), I receive the following error message:


      Macromedia flash player has stopped a potentially dangerous operation. The following application on your computer or network

      <name of file>

      is trying to communicate with this internet-enabled location

      <unknown>

      To let this application communicate with the internet, click settings.



      /********** FIRST CODE ****************/

      The first was from kirupa.com. The code on the button is:

      on (release) {
      //customize the window that gets opened
      // 0 equals NO.
      // 1 equals YES.
      address = " http://www.google.com";
      target_winName = "google";
      width = 400;
      height = 300;
      toolbar = 0;
      location = 0;
      directories = 0;
      status = 0;
      menubar = 0;
      scrollbars = 1;
      resizable = 0;
      //sends data back to the function
      _root.openWinCentre(address, target_winName, width, height, toolbar, location, directories, status, menubar, scrollbars, resizable);
      }

      The code on the root timeline is:

      _root.openWinCentre = function (url, winName, w, h, toolbar, location, directories, status, menubar, scrollbars, resizable) {
      getURL ("javascript:var myWin; if(!myWin || myWin.closed){myWin = window.open('" + url + "','" + winName + "','" + "width=" + w + ",height=" + h + ",toolbar=" + toolbar + ",location=" + location + ",directories=" + directories + ",status=" + status + ",menubar=" + menubar + ",scrollbars=" + scrollbars + ",resizable=" + resizable + ",top='+((screen.height/2)-(" + h/2 + "))+',left='+((screen.width/2)-(" + w/2 + "))+'" + "')}else{myWin.focus();};void(0);");
      }

      /********** SECOND CODE **************/

      The code on the button is:

      btn.onRelease = function()
      {
      getURL("javascript:window.open(' http://www.google.com','newWin','width=300,height=200,left=0,top=0,toolbar=No,location=No, scrollbars=No,status=No,resizable=No,fullscreen=No')");
      }

      Nothing on the root timeline.


      Anyone got a clue what’s happening? I was wondering whether there was problem with settings on my computer? Also, I do not want to embed JavaScript code in the HTML file.

      Many thanks,

      Essaeyu
        • 1. Re: JavaScript popup code not working 4 me
          kglad Adobe Community Professional & MVP
          your browser has a pop-up blocker?
          • 2. Re: JavaScript popup code not working 4 me
            SmpleJohn Level 1
            If you are viewing it from your computer it will block the pop up regardless of what you try to do. You have to publish it to view the pop up. I've tried changing my security settings and haven't had any luck yet. Let me know if you find a way to change them.
            • 3. Re: JavaScript popup code not working 4 me
              essaeyu Level 1
              kglad:

              I turned off the popup blocker and tested it but nothing changed. The getURL function, without the JavaScript, does open files in new windows which suggests that the problem is not with pop up but with JavaScript. I also tested the files on another computer but to no avail.

              SmpleJohn:

              Thanks for the reply but i didnt quite get it. If I am not viewing it from my computer, then from where shall i view it, u mean put it on a webserver? What I said was that when I access the SWF from HTML, nothing happens and when I play the stand-alone SWF (without being embeded in HTML), it gives a security warning.


              Now I have embedded the JavaScript code in HTML but again nothing has changed. When I click the swf button, no action takes place. The code on the swf button is:

              on (release)
              {
              getURL ("javascript:spawnWindow(' http://www.google.com','newwin','toolbar=no,location=no,status=no,menubar=no,scrollbars=ye s,resizable=yes,width=800,height=600')");
              }

              The code in the HTML file is:

              <script language="JavaScript">
              <!—
              function spawnWindow(URL,Name,features) { window.open(URL,Name,features);
              }
              //--></script>


              • 4. Re: JavaScript popup code not working 4 me
                kglad Adobe Community Professional & MVP
                that's not an actionscript issue. it's a javascript issue.

                different browsers interpret javascript differently. and many do not like pop-ups.
                • 5. Re: JavaScript popup code not working 4 me
                  essaeyu Level 1
                  Thanks for the reply but what is the way out then? I use IE 7 which shouldnt have issues with JavaScript. May be it has to do with the browser settings (I already diasbaled popup blocker) but so far it has ran websites with popup and JavaScripts.
                  • 6. Re: JavaScript popup code not working 4 me
                    SymTsb Level 2
                    rather than calling an external function that you've written, try calling just the window.open and see if it changes anything...
                    • 7. Re: JavaScript popup code not working 4 me
                      SmpleJohn Level 1
                      Have you tried uploading it to a server and testing the button? Maybe I'm missing something, but that usually is the problem for me. Apparently trying to access an external URL from your computer is "harmful". I'm glad Bill's got our backs on that one. I don't know what I'd do without him.
                      • 8. Re: JavaScript popup code not working 4 me
                        essaeyu Level 1
                        What I want to achieve is something very basic, done n times on the web, but its strange that its not working on my machine. I am getting popups through getURL function and on HTML links but not from swf/javascript links. This includes linking both to the webpages on the internet e.g. google and pages on my machine. I have tried three different ways of achieving this and am attaching thecode. Can someone look at the files please and see what’s wrong/spot something I overlooked? I will be extremely grateful.

                        Here is the code in the fla's (and html in one case). No facility to attach files else i would have done so. Though the flas/swf/html files can be downloaded from: http://www.actionscript.org/forums/showthread.php3?p=623694#post623694. These are three zip files posted by user essaeyu today.

                        Many thanks,

                        Essaeyu

                        /*************** Code in the first file ****************/

                        The code on the button is:

                        btn.onRelease = function()
                        {
                        getURL("javascript:window.open(' http://www.google.com','newWin','width=300,height=200,lef t=0,top=0,toolbar=No,location=No,scrollbars=No,sta tus=No,resizable=No,fullscreen=No')");
                        }

                        Nothing on the root timeline.

                        /*************** Code in the second file ****************/

                        /*Taken from kirupa.com*/
                        The code on the button is:

                        on (release) {
                        //customize the window that gets opened
                        // 0 equals NO.
                        // 1 equals YES.
                        address = " http://www.google.com";
                        target_winName = "google";
                        width = 400;
                        height = 300;
                        toolbar = 0;
                        location = 0;
                        directories = 0;
                        status = 0;
                        menubar = 0;
                        scrollbars = 1;
                        resizable = 0;
                        //sends data back to the function
                        _root.openWinCentre(address, target_winName, width, height, toolbar, location, directories, status, menubar, scrollbars, resizable);
                        }

                        The code on the root timeline is:

                        _root.openWinCentre = function (url, winName, w, h, toolbar, location, directories, status, menubar, scrollbars, resizable) {
                        getURL ("javascript:var myWin; if(!myWin || myWin.closed){myWin = window.open('" + url + "','" + winName + "','" + "width=" + w + ",height=" + h + ",toolbar=" + toolbar + ",location=" + location + ",directories=" + directories + ",status=" + status + ",menubar=" + menubar + ",scrollbars=" + scrollbars + ",resizable=" + resizable + ",top='+((screen.height/2)-(" + h/2 + "))+',left='+((screen.width/2)-(" + w/2 + "))+'" + "')}else{myWin.focus();};void(0);");
                        }

                        /*************** Code in the third file ****************/

                        Code in the html header

                        <script language="JavaScript">
                        <!--
                        function spawnWindow(URL , u_name)
                        {
                        var my_vin;
                        my_vin = window.open(URL , u_name);
                        }
                        //-->
                        </script>

                        Script in flash root timeline:

                        btn.onRelease = function()
                        {
                        getURL ("javascript:spawnWindow(' http://www.google.com','newwin')");
                        }
                        • 9. Re: JavaScript popup code not working 4 me
                          kglad Adobe Community Professional & MVP
                          your first code has some typos. extra spaces were introduced somehow.

                          correct those and retest in your browser. you should see a security warning from adobe when testing locally.
                          • 10. Re: JavaScript popup code not working 4 me
                            essaeyu Level 1
                            Thanks for the reply kglad. The first code did not have spaces in the actual file. May be vecause of copying and pasting, spaces have been introduced.

                            Anyways, when i launch the swf in browser, nothing happens when i click the button. When i launch it in the flash player, iu get a security warning. there is a settings op[tion, clicking on whcih, i am led to the macromedia website.
                            • 11. Re: JavaScript popup code not working 4 me
                              kglad Adobe Community Professional & MVP
                              you must launch the html file in the browser, NOT the swf.
                              • 12. Re: JavaScript popup code not working 4 me
                                essaeyu Level 1
                                Well i did both.

                                Anyways the problem has been resolved nearly. It was to do with the settings of the Flash player. I went to the website http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.ht ml and chose the Global Security Settings tab. In the ‘always trust files in these locations’ option I added the location/folder that contained my files. After that I restarted the browser and the code ran perfectly well.

                                So if you are testing your content locally in Flash player 8 or later, you need to explicitly designate your flash files/folders as trusted. Files will work fine if you upload them on a server. Right?
                                • 13. Re: JavaScript popup code not working 4 me
                                  kglad Adobe Community Professional & MVP
                                  correct.

                                  when you first tested your file (locally) you saw the warning and failed to ok the security settings so they weren't offered afterwards.