I would like to select all the text on a page, the software with the same result as if I pressed the button the combo the Ctrl + A .
The problem with use document.getSelection().selectAllChildren(body)is that the selection will also include text nodes that cannot be selected by the user, i.e. <script> </script>or nodes for which exists user-select:none, defined in CSS:
<div style="-moz-user-select:none"> Will be selected </div>
There is a method modifyfor selection objects, which can be used as follows:
selection.modify("extend", "forward", "documentboundary");
to extend the selection from the beginning of the document to its end, which will ignore any script element or style element and elements with -moz-user-select:none- unfortunately, Firefox does not allow documentboundaryas 3. an argument and worddoes not help much.
Is there a quick way to do this? Only need to work in Firefox.
EDIT (not a very good solution): Select the first node text, then use it selection.modify('extend', 'forward', 'line')several times, and selection.focusNodenot match the last node text - but depending on the length of the document, it takes a few seconds!
EDIT: selection.selectAllChildren Will work in Chrome, where text elements with user-select:nonewill not be selected - unfortunately, there is a different behavior in FF.
EDIT: , contenteditable, ;)