9 Replies Latest reply on Jul 15, 2009 10:01 PM by Sai_H

    Destroying an Iframe

    Sai_H

      I have a Iframe embedded in a canvas that is used as a popup. To navigate around the application, viewstacks have been used as containers.

      Now I close the popUp it works fine. But when I return back to the page, the Iframe is displayed.

       

      Any help around this would be appreciated.

       

      Thanks,

      Sai

        • 1. Re: Destroying an Iframe
          Madhav Subedi Level 4

          try removing all chidren of canvas before closing the popup.

          canvas.RemoveAllChildren();

          • 2. Re: Destroying an Iframe
            Sai_H Level 1

            Did that... Doesn't work...

            The Iframe is still retained.

            • 3. Re: Destroying an Iframe
              Madhav Subedi Level 4

              This may be due to the iframe is created by the wrapper( browser ) not the flex itself.

              I suggest you to have a look at DOM to inspect how the iframe object is generated, specifically its ID is same always or not.

               

              if you are sure that the generated IFrame ID ( for generated HTML DOM, not in the flex) is same always, then use ExternalInterface to remove that iframe before closing the popup.

              1 person found this helpful
              • 4. Re: Destroying an Iframe
                Sai_H Level 1

                Yeah, you are right. The HTML wrapper creates the IFrame.

                Thanks for the lead... I will try that and let you know.

                Thanks again,

                Sai

                • 5. Re: Destroying an Iframe
                  Sai_H Level 1

                  Wow, this took more than that I expected.

                  The IFrame.as needs to be changed. I haven't verified whether they have added this as a patch to the distribution.

                   

                  -->Add the javascript as a private variable to your IFrame.as

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                  private

                   

                   

                  static var

                  FUNCTION_DESTROYIFRAME:String =

                   

                   

                  "document.insertScript = function ()"

                  +"{ "

                  +"if (document.destroyIFrame==null)"

                  +"{"

                  +"destroyIFrame = function (frameID)"

                  +"{ "

                  +"var bodyID = document.getElementsByTagName(\"body\")[0];"

                  +"var olddiv = document.getElementById(frameID);"

                  +"bodyID.removeChild(olddiv);"

                  +"}"

                  +"}"

                  +"}";

                   

                  -->Add this to your createChildren() method

                  ExternalInterface.call(FUNCTION_DESTROYIFRAME);

                   

                   

                  -->Add the following method

                   

                   

                   

                   

                  public  function destroyChildren():void{

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                  ExternalInterface.call("destroyIFrame", frameId);

                  }

                   

                   

                  Now you can make a call to the destroyChildren of the Iframe from the popUp canvas.

                   

                  Thanks,

                  Sai

                   

                  • 6. Re: Destroying an Iframe
                    Madhav Subedi Level 4

                    create the function in the wrapper( html file), not inside flex itself.

                    • 7. Re: Destroying an Iframe
                      Sai_H Level 1

                      And why so???

                      • 8. Re: Destroying an Iframe
                        Madhav Subedi Level 4

                        as it is javascript, the better coding pattern would be to put it in browser ( in the index.template.html in html-templates folder if using flex builder ).

                        role of flex would be to call that function.

                         

                        in this very case, as IFrame component may face the situation where removing of the HTML IFrame is ofter encountered, it is good to place the code in the component itself, before distribution; but what i meant is, in general cases, as the JavaScript is browser script, it is better to put in the browser itself.

                        • 9. Re: Destroying an Iframe
                          Sai_H Level 1

                          I understand what you are hinting at.

                           

                          Thanks,

                          Sai