tags:

views:

102

answers:

4

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
A: 

You are correct. getSelection() returns an object. What is your question?

Jekke
I think it's fairly clear what his question is: "to get a string," he said.
T.J. Crowder
+1  A: 

.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.
KennyTM
Thanks for your answer . Where can i found full of javascript "class" .
nXqd
A: 

getSelection returns a Selection object. You can get the selected text by calling its toString method.

T.J. Crowder
A: 

text = document.getSelection()+''; alert(typeof(text)); // << it returns string

roviury