开发者

iframe across domain get value

开发者 https://www.devze.com 2023-01-17 18:28 出处:网络
How can I get the some value from other domain page? for example two page from different domain test.html:

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开发者_如何学JAVA="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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消