jQuery方法选择整个页面的内容

如何使用jQuery选择整个页面的内容以便以后复制到剪贴板,从而另一个WYSIWYG。

案例是:

$("#SelectAll").click(function(){ //CODE TO SELECT ALL THE CONTENTS OF THE CURRENT PAGE /* PS: $("body").focus(); $("body").select(); //doesn't work */ }); 

任何帮助表示赞赏。

谢谢

找到解决方案:

 function selectAll() var e = document.getElementsByTagName('BODY')[0]; var r = document.createRange(); r.selectNodeContents(e); var s = window.getSelection(); s.removeAllRanges(); s.addRange(r); } 

这在FF中工作还没有在其他浏览器中测试过。 只需要在任何我想要的地方调用selectAll。

 if ('createRange' in document && 'getSelection' in window) { // firefox, opera, webkit var range= document.createRange(); range.selectNodeContents(document.body); var selection= window.getSelection(); selection.removeAllRanges(); selection.addRange(range); } else if ('createTextRange' in document.body) { // ie document.body.createTextRange().select(); }