Reputation: 21
'A' is site with Javascript alert(document.domain);
'B' is the site.
Now my problem is that i want to iframe 'A' site under 'B', so that whenever I will open 'B' site , it should showme 'A' site with javascript popup (document.domain) of 'A'.
Here i coded something which is not working correctly, here it is running javascript under 'B' but i want it to run under 'A'.
<?php
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://mysites.com/index.php',
CURLOPT_USERAGENT => 'ghfhfh'
));
$resp = curl_exec($ch);
echo $resp;
echo $_SERVER['REQUEST_URI'];
curl_close($ch);
?>
This is the code in 'B' site index.
After opening 'B' site the javascript pops up 'B' 's domain not 'A'.
anyone help me please.
Upvotes: 2
Views: 111
Reputation: 29
If your goal is to share messages (like A site iframe loading, or pass event from A site iframe to parent B site), i think you should to use post Message.
With a few lines of code, you can create a two-way communication between the B site and the A site iframe. You'll need to write a simple Javascript in Site B for the reception of the message, specifying the site's domain of sender(origin), and a simple Javascript code within the site A (which will reside inside the iframe ) to send the message . Once in javascript, you can decide the time you send out the message from the site A.
The postMessage technology was used for so long by the various Facebook, Twitter, Youtube and allows you to solve this problem of cross domain.
Docs: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
Example: http://viget.com/extend/using-javascript-postmessage-to-talk-to-iframes
Let me know if you need help! ;)
Upvotes: 1