2013-11-28 27 views
3
<div class="cont"> 
    <iframe id="iframe" sandbox="" src="external_website" width="100%" height="100%" frameborder="0"></iframe> 
</div> 

我想用JQuery检测我是否从我的iframe中的其他网站获取内容?如何检查内容是否存在于带有外部源的iframe中

我试过不同的事情,没有什么帮助。 谢谢。

+0

您无法访问来自不同域的iframe的内容。 – Barmar

+0

你应该能够检查src是本地还是外部。 – techfoobar

+0

你在沙箱中的iframe,不允许脚本或任何东西交叉原点,所以为什么你会加载一个跨源URL到沙盒的iframe – adeneo

回答

-1
$("#myiframe").contents().find("#myContent") 


<html> 
<head> 
<title></title> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script> 
<script type="text/javascript"> 

$(function() { 

    //here you have the control over the body of the iframe document 
    var iBody = $("#iView").contents().find("body"); 

    //here you have the control over any element (#myContent) 
    var myContent = iBody.find("#myContent"); 

}); 

</script> 
</head> 
<body> 
    <iframe src="mifile.html" id="iView" style="width:200px;height:70px;border:dotted 1px red" frameborder="0"></iframe> 
</body> 
</html> 
+0

是的,但这不适用于其他领域。并且必须使用属性沙箱。 – Adam

相关问题