0

My main page loads an iframe which contains a Flex application (which occupies part of the screen).

The flex app has a "Cancel" button which should make the main page navigate to a different location using a JavaScript method in the main page ("goBack()").

I tried to use this Flex - AS code for the "Cancel" button with no luck (it tried to invoke JS function using the parent object):

    public function cancel(){
        flash.external.ExternalInterface.call("parent.goBack()");
    }

This is the JavaScript code

   function goBack(){
          window.top.location='some_URL';
   }

Appreciate your thoughts

Update:

i find out I get the following error when trying to invoke the JS method:

     "Blocked a frame with origin https://SITEA from accessing a cross-origin frame."
Uri Lukach
  • 1,093
  • 1
  • 14
  • 28
  • This should be simple - make sure the main page and your iframe page are both loaded from the same server. – Brian Sep 10 '14 at 17:24

2 Answers2

0

According to Calling a parent window function from an iframe, you're on the right track for calling your main page goBack() function.

Try adding a javascript function to your iframe-loaded page:

function iframeGoBack() {
    window.parent.goBack();
}

Then call that from ExternalInterface

Alternatively, if you know the desired URL, you could switch to using navigateToURL() inside your Flex code.

Community
  • 1
  • 1
Brian
  • 3,850
  • 3
  • 21
  • 37
  • Unfortunately using window.parent is not working. I don't see navigateToLocation, I tried to use navigateToURL but it change the iframe URL and I need to change the main page URL – Uri Lukach Sep 10 '14 at 15:32
  • Oops, I meant navigateToURL. If you `alert(window.parent);` in your iframe, what do you see? – Brian Sep 10 '14 at 15:52
  • I have the URL to navigate to, I have an issue with directing the main page to this URL from my IFrame – Uri Lukach Sep 10 '14 at 16:05
0

From what I have seen there are a lot of limitations when trying to invoke JS methods between different origins (for instance, iframes from different domains/ports).

I bypass the issue by using the IFrame-Flex app to call the main page "history->back" method:

          flash.external.ExternalInterface.call("window.history.back()");

That is working fine.

I also noticed that there is a special library for communications between different origins called easyxdm

http://easyxdm.net/wp/

I didn't use it, but it get lots of community endorsement.

Uri Lukach
  • 1,093
  • 1
  • 14
  • 28