Collapsed selection in Opera

I cannot get the start and end offsets of the select object in Opera (v9.50) when the selection is collapsed (i.e. just hover and click instead of selecting text). This is my simple test code that works in FF and Safari but doesn't 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 text it works, but just pointing and clicking always returns the offsets as 0. What am I missing? Thanks in advance.

+1


source to share


2 answers


Opera doesn't make a selection when you click. I don't know what you are trying to achieve, but if you want to get selected text for example, Opera also implements "document.selection" (perhaps to support other IE scripts), so you can do things like "document.selection .createRange (). text "(not very useful because when nothing is selected it returns an empty string).



I think you are out of luck with that.

+1


source


I would suggest posting this on the Opera forums, because there must be someone (eg dev) who can give you a definite "yes" or "no".



Opera Forum

+1


source







All Articles