日期:2014-05-16  浏览次数:20332 次

如何选择并复制iframe 子页面中的内容
a.html   中有个 <iframe   src= 'b.html '   xxx> </iframe>

怎么样在a.html中用js把b.html的内容全部复制到系统剪贴板

谢谢

------解决方案--------------------
a.html 中有个 <iframe src= 'b.html ' name= "myframe "> </iframe>
var tmp= " <html> "+myframe.document.getElementsByTagName( "HTML ").item(0).innerHTML+ " <html> ";

tmp即为iframe的所有源码。
然后再考虑copy系统剪贴板中。//没有使用过系统的这些东西,估计是使用控件之类
------解决方案--------------------
楼上的~~
myframe.document等同于document
也就是取到了元素所在的document对象~~而不是元素的document对象~~~

------解决方案--------------------
<iframe src= "1.htm " id= "iframes " marginWidth= "10 " marginHeight=10 frameborder= "0 " width= "100% " height= "100% " scrolling= "no "> </iframe>
<input type= "button " value= "复制iframe中页面的源码到剪切板 " onclick= "copyviewsource() ">
<script>
function copyviewsource(){
var tmp= " <HTML> "+window.frames[ 'iframes '].document.getElementsByTagName( 'HTML ')[0].innerHTML+ " </HTML> ";
alert(tmp);
window.clipboardData.setData( 'text ', tmp);
}
</script>


引用iframe中嵌入页面的相关属性,使用window.frames[ 'iframeid ']
引用iframe的相关属性,使用document.getElementById( 'iframeid ')
------解决方案--------------------
无稽之谈

框架内桢的document对象这样获取
document.getElementById( "iframeid ").contentWindow.document