4 Replies Latest reply on Feb 15, 2011 5:50 AM by Raul HUDEA

    HTML control: How to use window.open programmatically?

    Stenrap2

      Hi all,

       

      I've been banging my head against this for hours, so I hope someone can help!

       

      My AIR application has  an HTML control, and I've set its "htmlHost" property to an instance of a custom class that extends HTMLHost (so that my application has support for all the common JavaScript properties and methods). Sure enough, if I manually click on a link whose href attribute has a value of "javascript:window.open(...)", then a new window of the correct size does open to the correct  URL as expected.

       

      However, if I try to programmatically open the exact same window (by calling html.domWindow.open(...)), absolutely nothing happens!

       

      I'm happy to post the relevant code if necessary, but first I'd like to know whether this is already a known issue (Google leads me to believe it is, but I haven't found a concrete bug report). Is this in fact a known issue? If so, is there a workaround that does not involve open new windows in the system browser?

       

      Thanks,

      Rob

        • 1. Re: HTML control: How to use window.open programmatically?
          Stenrap2 Level 1

          I found an interesting quote on a Flex 3 help page. The first part seems to describe exactly what I'm seeing...

           

          "Window.open() function When called by code running in a non-application sandbox, the open() method only opens a window when called as a result of user interaction  (such as a mouse click or key press)."

           

          ...but the next part does not describe my situation:

           

          "In addition, the window title is  prefixed with the application title (to prevent windows opened by remote  content from impersonating windows opened by the application). For more  information, see the Restrictions on calling the JavaScript Window.open() method."

           

          As I said in my original post, I'm not seeing any window at all if I call window.open() programmatically. And if I manually click on a link that opens a popup window, its title is not prefixed with the title of my application.

           

          I don't think my code is running in a non-application sandbox, but how can I be sure?

          • 2. Re: HTML control: How to use window.open programmatically?
            Joe ... Ward Level 4

            What happens if you set the htmlHost property to "new HTMLHost( true );" That should give you default browser-like behavior which you can compare to the behavior of your custom host class.

             

            Where is the HTML file that you are loading? If it is anywhere else besides the application directory, then it will be loaded in a non-app sandbox.

            • 3. Re: HTML control: How to use window.open programmatically?
              Stenrap2 Level 1
              Where is the HTML file that you are loading? If it is anywhere else besides the application directory, then it will be loaded in a non-app sandbox.

               

              This must be the reason then. I'm loading a page on a remote web server.

               

              Is there any way to override this non-application sandbox behavior? If not, I have a workaround that detects the popup location and programmatically creates a new HTMLLoader in a new NativeWindow. However, with this approach the HTMLLoader on the popup window is unable to access/refresh the HTMLLoader on its opener window (even though I'm manually setting the window.opener property). Is there some way to make the new HTMLLoader "aware" of its opener?

              • 4. Re: HTML control: How to use window.open programmatically?
                Raul HUDEA Adobe Employee

                Hi,

                 

                Did you manage to solve your issue ? If not, attaching a sample code exhibiting the behavior would be very useful in this case.

                 

                 

                Thanks,

                Raul