2 Replies Latest reply on Aug 14, 2009 12:16 PM by Joe ... Ward

    loading all website links in one window


      Does anyone know how to capture / prevent links from opening a new window in Air?

      I am an ajax developer and I have several sites that load in an iframe in my air application.

      One of the sites has links that open in a new window. Is there anyway to keep it from openning in a new window and instead, open the link in the iframe?

      I don't own those sites so no, I can't just change the target on the links themselves.


        • 1. Re: loading all website links in one window
          dwbiz05 Level 1

          Anyone know if this can be done by somehow overriding the window.open function? or maybe air.HTMLLoader.createRootWindow function?

          Obviously in the override I would have to capture the urlrequest and put it in the iframe src.

          Any ideas?

          • 2. Re: loading all website links in one window
            Joe ... Ward Level 4

            One approach would be overriding window.open. However, this can only be done in ActionScript since it requires extending a class. There's an example in the AIR Developer's guide (which I see you have commented on already). Your situation is a bit more complicated than the examples in the docs because you are loading remote content into an iframe. You might have to experiment to figure out if the HTMLHost location() functions are called when a link in an iframe is followed. (I don't know.) If so,  you could try passing a reference to the iframe object to your HTMLHost class when you create it and use that reference to load the URL given to you by the location() function's locationURL argument into the correct place.


            Another tactic would be to walk the DOM of the iframe and rewrite the link objects so that they open in the same window.


            Still another would be to intercept an appropriate event on the iframe object and prevent the default behavior so that you can force the link to load in the desired iframe.


            (Using  air.HTMLLoader.createRootWindow wouldn't help here as it creates an entirely new window.)