<iframe src="" name="bb" id="iframe1" ></iframe>
<div onclick="test()">tesxr</div>
<div onclick="bobo()">bbb</div>
<script type="text/javascript">
window.open('http://wenku.baidu.com/view/30f1188fd15abe23482f4dcc.html','bb');
//将http://wenku.baidu.com的内容放入iframe中,为跨域
window.open('./base.html','bb');
//把同域中的内容放入iframe中,为同域
function test(){
console.log(window.document.getElementsByTagName('iframe')[0].contentWindow.document);
//可获取同域中的对象,但是不能获取跨域的console.log(window.document.getElementsByTagName('iframe')[0].contentWindow.document);
var html=window.document.getElementsByTagName('iframe')[0];
console.log(html);
//通过console.log可以打印出跨域iframe中的内容,为一个object 但是无法将其转换为字符串!!!!?是个问题~`
htmlS=html.toString;
htmlT=JSON.stringify(html);
htmlW=html.toString()
console.log(JSON.stringify(html))
var htmlStr=JSON.stringify(html);
alert(html.toString())
var substr = htmlStr.match(/body(\S*)body/);
alert(substr)
console.log(window.document.getElementsByTagName('iframe')[0]);
}
function bobo(){
alert(htmlS);
alert(htmlT);
alert(htmlW)
}
</script>
iframe 获取值无法将console.log的对象转换为 string
最新推荐文章于 2024-11-30 09:00:00 发布
