您的位置:首页 > 其它

iframe 获取值无法将console.log的对象转换为 string

2017-03-14 22:25 363 查看
<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐