jQuery方法来选择整个页面的内容 [英] jQuery Method to select the contents of a whole page
本文介绍了jQuery方法来选择整个页面的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用jQuery选择整个页面的内容,以便稍后复制到剪贴板,从而复制另一个所见即所得.
How can I select the contents of the whole page using jQuery for later to be copied to clipboard and hence another 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.
This works in FF haven't tested in other browsers. Just need to call selectAll wherever I want.
推荐答案
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();
}
这篇关于jQuery方法来选择整个页面的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文