PDA

View Full Version : problem with document.selection



---dom---
03-23-2006, 02:23 PM
Hi,


Wat I'm tryin to do is read in some text using:

function getSelectedText() {
if (document.selection) {
var range = document.selection.createRange();
document.body.createTextRange();
var str =range.text.toString()

return str;
}
}

then add str to the search string for google using:

function googleSearch()
{
var target='http://www.google.com/search?q=';
var str = getSelectedText();
self.name = "body";
msgWindow = window.open(target + str);
}


and finally call it through a context menu.

However the google search returns [object] or nothing.


Any ideas???

Twey
03-23-2006, 04:03 PM
For a start, don't rely on document.selection. It's IE-only.

---dom---
03-24-2006, 12:46 PM
document select only works for IE4 and up, but for the project i'm doing its all thats necessary