views:

121

answers:

2

Hello,

I am not able to get the selection object's start and end offsets in Opera (v9.50) when the selection is collapsed (i.e. just point and click instead of highlighting text). This is my simple test code, which works in FF and Safari but does not work in Opera.

<html>
<head>

<script type="text/javascript">
    function showSelection()
    {
     userSelection = window.getSelection();
     alert('Start: '+userSelection.anchorOffset+'\nEnd: '+userSelection.focusOffset);
    } 
</script>

</head>

<body>

    <div onmouseup="showSelection();">
     <p>Lorem ipsum dolor <strong>sit amet</strong></p>
    </div>

</body>
</html>

When I select a text, it works, but just pointing and clicking always return the offsets as 0. What am I missing? Thanks in advance.

+1  A: 

Opera does not seem to make a selection when you click. I don't know what you're trying to achieve, but if you for instance want to get the selected text, Opera also implements 'document.selection' (probably to support otherwise IE only scripts) so you can do things like "document.selection.createRange().text" (not very helpful, because when nothing is selected it will return an empty string).

I think you're out of luck with this one.

eelco
+1  A: 

I would suggest putting this one on the Opera forums, there is bound to be someone (a dev, for example) who could give you a definite yes or no.

Opera forum

SCdF