<p>Finding out what's selected in real browsers is as simple as:</p>

<pre><code>var range = {
  start: textbox.selectionStart,
  end: textbox.selectionEnd
}
</code></pre>

<p>But IE, as usual, doesn't understand. What's the best cross-browser way to do this?</p>

My current solution is verbose and based on
this thread
, but I'm open to better solutions.
```
```
function getSelection(inputBox) {
    if ("selectionStart" in inputBox) {
        return {
            start: inputBox.selectionStart,
            end: inputBox.selectionEnd
        }
    }

    //and now, the blinkered IE way
    var bookmark = document.selection.createRange().getBookmark()
    var selection = inputBox.createTextRange()
    selection.moveToBookmark(bookmark)

    var before = inputBox.createTextRange()
    before.collapse(true)
    before.setEndPoint("EndToStart", selection)

    var beforeLength = before.text.length
    var selLength = selection.text.length

    return {
        start: beforeLength,
        end: beforeLength + selLength
    }
}
```
```