views:

22

answers:

2

How can I get the some value from other domain page?

for example

two page from different domain

test.html:

code:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
 <span id="data"></span>
 <iframe name="dd" src="http://otherdomain.com/innerpage.html" style="width:600px;height:500px;"></iframe>
</div>
</body>
</html>

innerpage.html(on another domain)

code:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
 function SendDataToParent(){
  var dataId = parent.document.getElementById("data"),
   data = document.getElementById("iframeData").value;
   dataId.innerHTML ="<input type='hidden' value='"+data+"' name='dataFromChildIframe'/>";

 }
</script>
</head>
<body>
<div>
 <button onclick="SendDataToParent();">SendDataToParent</button>
 <input type="text" id ="iframeData" value="some content here">
</div>
</body>
</html>

I want to get input with the id of iframeData value ,and send this value to the parent page

but code don't work ,How to do this?

+1  A: 

For security reasons, it is completely impossible to pages in two different domains to communicate on the client in current browsers.

As a workaround, you can use JSONP in both pages.

SLaks
A: 

This is not allowed due to the cross-domain security policy implemented as part of the sandbox in all browsers.

Alexander Sagen