Opera bug with JS autoselecting text (if more than 1 div)
Posted
by
E L
on Stack Overflow
See other posts from Stack Overflow
or by E L
Published on 2012-11-29T18:18:18Z
Indexed on
2012/12/03
11:14 UTC
Read the original article
Hit count: 142
Here is HTML code. It supposed to select all text in "Container" div
<B onclick="SelectText(document.getElementById('Container'));">select all text</B>
<Div id="Container">
<Div>123456</Div>
<Div>123456</Div>
<Div onclick="SelectText();">123456</Div>
</Div>
here is JS code of the SelectText() function
function SelectText(target){
if(target==null){
var e = window.event || e;
if (!e) var e = window.event;
var target=e.target || e.srcElement;
}
var rng, sel;
if ( document.createRange ) {
rng = document.createRange();
rng.selectNode( target );
sel = window.getSelection();
sel.removeAllRanges();
sel.addRange( rng );
} else {
var rng = document.body.createTextRange();
rng.moveToElementText( target );
rng.select();
}
}
Problem is that in Opera 12.02 when "select all text" is clicked, all text seems like selected, but it's not selected (I can't rightclick it and copy).
(terrific, but IE works fine with it)
Why not in Opera?!!! And what can I do to make Opera 12.02 believe that all text in "Container" is selected?
© Stack Overflow or respective owner