JQuery Method for selecting the contents of an entire page

How can I select the contents of an entire page using jQuery for later copying to the clipboard and therefore another WYSIWYG.

The point is this:

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

Any help is appreciated.

thank

FOUND SOLUTION:

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

This works in FF, which have not been tested in other browsers. You just need to call selectAll wherever I want.

+2
source share
1 answer
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();
}
+6
source

All Articles