Cross-domain JavaScript with child subdomains

I have two web application settings:

david .example.com and john .example.com

David opens a new window to John:

window.open('john.example.com');

Now, John would like to set the input element back to David:

$("#input", window.opener.document).val("Hello David.");

My problem is that this does not work in most modern browsers due to the security of cross-domain scripting. I also tried to set document.domainfor different combinations of domains for both David and John without success.

The only time this works is if John is on example.com, and both options are document.domainset to example.com. However, it example.comis our main website and is not available as a solution.

How can I make the above example when the solution works in all modern security browsers?

Notes

  • I manage example.comall its subdomains.
  • David and John are separate web applications and cannot be hosted on the same subdomain.
+5
source share
2 answers

You should be able to do this while you set document.domain on both DOMs.

document.domain = location.host.replace(/^.*?([^.]+\.[^.]+)$/g,'$1');

Paid by Martin Jespersen

+8
source

iframes -. . . , Facebook connect. , , .

-1

All Articles