Forum Moderators: open

Message Too Old, No Replies

Cross Domain Scripting in Iframes

2-Way JavaScript communication between different domains

         

skyzhere

9:48 am on Jul 13, 2009 (gmt 0)

10+ Year Member



I am using MDI windows in my application where all the windows are opened in iframes inside a parent iframe.

I have 3 sources of content vended from 3 domains:

appl.example.com
forms.example.com
ebanking.example.com

The main client application and is being vended from appl.example.com.
Depending upon the link in the main application I'm loading content from forms.example.com or ebanking.example.com within an iFrame in a JSP via a URL.

I need to enable 2-way Javascript communication from the appl.example.com frames to the forms.example.com frame.
So to allow cross frame/domain scripting I need to drop the domain from "appl.example.com" to "example.com" by setting the document.domain property.
The called content on "forms.example.com" also needs to drop its domain to "example.com".

This works fine and I can call out to the "forms" content successfully.

However, now that I've dropped the domain down to "example.com" I can't access the javascript content within "appl.example.com" anymore. Apparently if I explicitly set my document.domain property then I can't access any other content that doesn't also explicitly set its document.domain (even if the document.domain property in question is the default - if both pages don't set it to the same value then no communication is possible).

So really what I need help with is a way to allow this 2-way conversation to take place without jeopardizing the rest of the communication within the client application. Does the document.domain property work for child frames? By that I mean; If I set the document.domain property in the parent Iframe, then will it also apply to all the child frames?

Is there any place where I can set the document.domain to "example.com" globally so that it works fine with all the domains set to "example.com".

[edited by: engine at 11:08 am (utc) on July 13, 2009]
[edit reason] Please use example.com [/edit]

daveVk

12:05 pm on Jul 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



However, now that I've dropped the domain down to "example.com" I can't access the javascript content within "appl.example.com" anymore

Even if on same domain, you can not directly reference javascript in another window or frame. Check how you are going about this. You say "anymore" was it working prior to dropping domain down.

skyzhere

12:42 pm on Jul 13, 2009 (gmt 0)

10+ Year Member



Thanks daveVk.

I access the JavaScript from other frames using the frame name suffix, so it works throughout the application without any issues.

Yes, before dropping the domain down all was working fine with in "appl.example.com"( But I was not able to access content from "forms.example.com"). Now I am allowed to raise my domain back to its original setting of "appl.example.com" however, I still cannot access the "appl.example.com" content.

This seems obvious since; "If I explicitly set my document.domain property then I can't access any other content that doesn't also explicitly set its document.domain (even if the document.domain property in question is the default - if both pages don't set it to the same value then no communication is possible)."

That is why I need some help as to how can I set the domain property globally to make the set-up work.

daveVk

10:57 pm on Jul 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Each iframe is a separate window so each window.document.domain needs to be set separately, say within it own window.onload function.

It may be useful to post code snippets of what works and what does not.