将表单发布到iframe并使用javascript从iframe获取内容?
我在一个网站上工作,我需要从iframe获取内容。 代码在这里将表单发布到iframe并使用javascript从iframe获取内容?,javascript,iframe,cross-domain,Javascript,Iframe,Cross Domain,我在一个网站上工作,我需要从iframe获取内容。 代码在这里 <!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-lates… </head> <body> <iframe src="http://glimmertech.org/IF222.htm" width="80%" height="600" id="fra
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-lates…
</head>
<body>
<iframe src="http://glimmertech.org/IF222.htm" width="80%" height="600" id="frameDemo"> </iframe>
<script>
var myFrame = $('#frameDemo');
myFrame.load(function()
{
var myjQueryObject = $('#frameDemo').contents().find('#newid'…
alert(myjQueryObject[0].innerHTML);
});
</script>
</body>
</html>
试试这个:
var myIframe = document.getElementById('frameDemo');
var myObject = myIframe.contentWindow.document.getElementById('newid');
alert(myObject.innerHTML);
您无法访问其他域上的iFrame。如果可以在同一个域(可能是代理服务器?)上使用$.contents()对不起,这不正确,因为iframe来自另一个域