I use the window.getSelection() method on my project to make a quotable text
It's working just fine in all modern browsers, exept IE10. In IE10 console returns correct text, but the selection is broken.
The only code I used:
text = window.getSelection().toString();
console.log(text);
This code calls on mouseup event.
Does anyone know the solution?
@Alex IE prior to 9 does not implement getSelection (). The code works for me in Chrome 8. I selected the text and clicked the button, and the text became red, so something works. @Alex Your demo works in all current browsers ( IE9, FF4, Chrome 10, Safari 5, and Opera 11). +1 This is a great getSelection demo.
The getSelection () property of the Document interface returns a Selection object representing the range of text selected by the user, or the current position of the caret. None. A Selection object. Some functions (like Window.alert ()) call toString () automatically and the returned value is passed to the function.
Document.getSelection () The getSelection () property of the Document interface returns a Selection object representing the range of text selected by the user, or the current position of the caret.
You can call Window.getSelection (), which works identically to Document.getSelection () . It is worth noting that currently getSelection () doesn't work on the content of <input> elements in Firefox. HTMLInputElement.setSelectionRange ()) could be used to work around this.
try this should work for ie < 9.0
var texttest = document.selection.createRange();
alert (texttest.text);
this is for all browsers except ie < 9.0
var texttest = document.getSelection();
alert(texttest);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With