从iframe获取数据 [英] Get data from iframe
本文介绍了从iframe获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
iframe
,我希望从 iframe
到 jquery
。 这是我的代码:
< html>
< head>< script src =http://code.jquery.com/jquery-1.9.1.min.js>< / script>
< script type =text / javascript>
函数copyIframeContent(iframe){
var iframeContent = $(iframe).contents(); //警报(iframeContent);
//$(\"#result\").text(\"Hello World);
$(#result)。html(iframeContent.find('body')。html); alert(iframeContent.find('body')。html());
}
< / script>
< / head>
< body>
< iframe id =myIframeonload =copyIframeContent(this); name =myIframesrc =text.php>< / iframe>< br />
结果:< br />
< textarea id ='result'>< / textarea>
< input type =buttonvalue =clickid =btnonclick =aa()>
< script type =text / javascript>
函数aa(){alert(Fdf);
alert(document.getElementById('myIframe')。contentWindow.document.body.innerHTML);
}
< / script>
< / body>
< / html>
text.php:
text to change
我在所有浏览器中都尝试了很多,但仍然是这样不工作。
任何人都可以帮助我获得这些内容吗?
$('#myIframe')。contents()
更新:
在OP中:
$(#result) html的(iframeContent.find( '主体')的HTML。);
应该说:
$( #结果)的HTML(iframeContent.find( '主体')的html());
I am doing this first time. I have created an iframe
on my page and I want the text from the iframe
through jquery
.
Here is my code :
<html>
<head><script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
function copyIframeContent(iframe){
var iframeContent = $(iframe).contents(); //alert(iframeContent);
//$("#result").text("Hello World");
$("#result").html(iframeContent.find('body').html);alert(iframeContent.find('body').html());
}
</script>
</head>
<body>
<iframe id="myIframe" onload="copyIframeContent(this);" name="myIframe" src="text.php"></iframe><br />
Result:<br />
<textarea id='result'></textarea>
<input type="button" value="click" id="btn" onclick="aa()">
<script type="text/javascript">
function aa(){ alert("Fdf");
alert(document.getElementById('myIframe').contentWindow.document.body.innerHTML);
}
</script>
</body>
</html>
text.php:
text to change
I tried a lot in all browsers but still this is not working. Can anyone help me to get this content?
解决方案
Use .contents() to get to iFrame's DOM.
$('#myIframe').contents()
UPDATE:
In the OP:
$("#result").html(iframeContent.find('body').html);
Should say:
$("#result").html(iframeContent.find('body').html());
这篇关于从iframe获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文