Can a Selection object be created without any user interaction? window.getSelection()returns an object Selection, but you cannot change () if the user does not have his choice.
window.getSelection()
Selection
Is it possible to create a selection that starts with the very first element on the page, and then can make modify()it, without having to do anything?
modify()
Example: http://jsfiddle.net/niklasvh/L5M3U/
It doesn’t select anything when the page loads, but if you click on something, you’ll make a choice.
, , , addRange(). , <body> , :
addRange()
<body>
function selectBody() { var range = document.createRange(); range.selectNode(document.body); var sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(range); } window.onload = selectBody;
IE < 9, .