Results 1 to 3 of 3

Thread: problem with document.selection

  1. #1
    Join Date
    Mar 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default problem with document.selection

    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???

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    For a start, don't rely on document.selection. It's IE-only.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    document select only works for IE4 and up, but for the project i'm doing its all thats necessary

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •