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

来源:互联网 发布:源码交易系统 编辑:程序博客网 时间:2024/06/03 17:47
<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>
0 0
原创粉丝点击