lanqy
lanqy

Reputation: 3021

iframe across domain get value

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?

Upvotes: 0

Views: 500

Answers (1)

SLaks
SLaks

Reputation: 887433

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.

Upvotes: 2

Related Questions