jquery如何获取页面中引入iframe网页的内容

<iframe src="ip.html" target="_self" id="if"></iframe>此为index.html中的iframe,我想在index.html页面中使用jquery获取引入页面的内容,求解
3楼:你说的那个我试过了,Uncaught SecurityError: Blocked a frame with origin "null" from accessing a frame with origin "http://iframe.ip138.com". The frame requesting access has a protocol of "file", the frame being accessed has a protocol of "http". Protocols must match.不知道怎么回事,其实我就是想用java获取外网ip,做一个【您所在IP申请的短信验证码数已经达到上限】这个功能,如果有其它方法,大家尽管推荐,谢谢!

//jquery在父窗口中获取iframe中的元素
//1、获取页面firame1的html内容
$("#iframe1").contents().find("#form1").html()
//获取iframe内的网页标题
$("#iframe的ID").contents().attr("title");//jquery 方法1
//类似的方法
$(selector, window.top.document); 
$(selector, window.opener.document); 
$(selector, window.top.frames[0].document);

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-06-18

qkqqqqkqqq推荐的文章我也看了,不知道楼主试过没有,我试了下只有

$(document.getElementById('iframeId').contentWindow.document.body).html()

这个成功了,其他都说我缺少函数,可能是JQ版本的问题

本回答被网友采纳
第2个回答  2014-12-19
你iframe跨域访问了啦,要想获取IP,有很多第三方的API的,如腾讯,新浪,淘宝等都有提供API你直接调用就行了,具体的你可以百度一下 IP地址库 api
第3个回答  2014-06-18
第4个回答  2014-06-18
$("#if").html()
这个搞不到??