I'm new to javascript : I use window.getSelection() to get a string . But it returns an object.
var text = '';
text = document.getSelection();
alert(typeof(text)); // << it returns object
I'm new to javascript : I use window.getSelection() to get a string . But it returns an object.
var text = '';
text = document.getSelection();
alert(typeof(text)); // << it returns object
You are correct. getSelection() returns an object. What is your question?
.getSelection() returns a DOMSelection object. The DOMSelection class contains a .toString() method to turn it into a string.
So
var str = window.getSelection().toString();
alert(typeof(str)); // string.
getSelection returns a Selection object. You can get the selected text by calling its toString method.
text = document.getSelection()+''; alert(typeof(text)); // << it returns string