Forum Moderators: open

Message Too Old, No Replies

Opera & selecting text in a <div>

         

try_again

12:05 am on Jul 3, 2004 (gmt 0)



Hi All

I have been trying for what seems almost a week, to find a way to be able to get Opera to just select what is in a div tag!

In

Netscape/Mozilla, I can do it like so....

<script>
function csb(x_code)
{

var dt = document.createRange();
dt.selectNode(document.getElementById(x_code));
window.getSelection().removeAllRanges();
window.getSelection().addRange(dt);
}
</script>
<div id='php_code'>some code</div>
<input type='button' value='Select!' onclick="csb('php_code');">

In IE......

<script>
function csb(x_code)
{

var dt = document.body.createTextRange();
dt.moveToElementText(document.getElementById(x_code));
dt.select();
}
</script>
<div id='php_code'>some code</div>
<input type='button' value='Select!' onclick="csb('php_code');">

It seem like there is no select methods for Opera unless it is doc type HTML!

So please if you know how to do this in Opera, please show me...

Thanks...

Randy

Rambo Tribble

4:15 am on Jul 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Neither the IE document.selection or the NN 6+ window.getSelection() is codified in the W3C's DOM specifications. They are individual, proprietary approaches to the issue and are not particularly likely to be supported by other browsers. The only standardized use of the select() method is for text within form elements, most of which are part of the DOM 1.