www.webdeveloper.com
Results 1 to 4 of 4

Thread: get the selected text in JavaScript

  1. #1
    Join Date
    Sep 2013
    Posts
    2

    get the selected text in JavaScript

    I'm building a JS bookmarklet which allow user to capture URL that has selected in their browser and sends it off to a web app.....

    Instead of capture the URL from the navigation bar i can capture the url selected on a website?

    Code:
    javascript:var%20e=document.createElement('script');e.setAttribute('language','javascript');e.setAttribute('src','https://server/bookmarlet/load.js?url='+encodeURIComponent(location.href));document.body.appendChild(e);void(0);

  2. #2
    Join Date
    Jun 2008
    Posts
    106
    Code:
    window.getSelection().toString()

  3. #3
    Join Date
    Nov 2002
    Location
    Flint, Michigan, USA
    Posts
    590
    Code:
    function GetSelected(What) {
      var Value;
      if (window.getSelection) {
        Value=window.getSelection();
      } else {
        if (document.getSelection) {
          Value=document.getSelection();
        } else {
          Value=document.selection.createRange().text;
        }
      }
      if (Value == '') {
        if (What) {
          Value=prompt(What,'');
        }
      }
      return Value+'';
    } // GetSelected

  4. #4
    Join Date
    Sep 2013
    Posts
    2
    thanks guys

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles