1

Page A and page B are on different domains.

A is iframed on page B.

I need to call a function which is on page B from page A.

Is this possible without something like porthole?

Basically what I'm trying to do is a simple push notification (A notifies B), don't need to transfer any content.

5
  • Do you have control over both domains? Commented Aug 21, 2011 at 6:20
  • Well sort of. I have full control of A, and I can convince owner of B to put a function/script on his page. Commented Aug 21, 2011 at 6:23
  • Well, you might be able to use this: window.postMessage. (Note: it's a rather new API) Commented Aug 21, 2011 at 6:25
  • Which browsers will it not work with? Commented Aug 21, 2011 at 6:29
  • Mostly IE7 and below. It works with FF3+, IE8+, Chrome, Safari 5, Opera 10+ (see this question) Commented Aug 21, 2011 at 6:32

3 Answers 3

1

There is an HTML5 way to do this with cross window messaging.

There are various work-arounds when HTML5 isn't available that can be used even between different origins.

Sign up to request clarification or add additional context in comments.

Comments

0

If you want to avoid using that specific library you could use the concept it's based off of and roll your own. Here's a pretty in depth article that describes the technique without the use of a library: http://softwareas.com/cross-domain-communication-with-iframes.

Comments

0

Put A and B with the same domain, different subdomain is fine. Then in the iframe A, you can call parent.function_name (parameter1, parameter 2). If you need to call that function very often, you may want to do this :

function p(data, div_id){parent.p(data, div_id);}  

then in iframe A, you can just call p(data, div_id), which will actually call page B's function. I have used this a lot of comet streaming. If you are interested, you may read this, which basically use iframe to communicate with data:

http://www.shanison.com/2010/05/10/stop-the-browser-“throbber-of-doom”-while-loading-comet-forever-iframe/

2 Comments

subdomain solution is not an option.
Is there any reason not to just do "var p = parent.p;"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.