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开发者_如何学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.
精彩评论