Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9160889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:50:39+00:00 2026-06-17T13:50:39+00:00

I have spent several hours searching the web for solutions. What I would like

  • 0

I have spent several hours searching the web for solutions. What I would like to do is take the highlighted text on a page and transfer it to a textarea in the popup.html of the chrome extension. I was wondering if someone could supply me with suggested source code of an extension that could do this.

This is the most pertinent thread I looked at that i thought would be most helpful – query is similar. Button in popup that get selected text – Chrome extension

I tried copying the code and running it as an extension, it does not obtain the highlighted text. Was wondering if anyone had any suggestions and how to solve this problem. Thank you very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:50:40+00:00Added an answer on June 17, 2026 at 1:50 pm

      Well just like the answer to the question you linked, you will need to make use of Message Passing and Content Scripts. That code is over 2 years old though and makes use of depreciated methods such as onRequest and getSelected. A few simple modifications should be plenty to update it to the new api’s.

    Popup.html

    <!DOCTYPE html> 
    <html>
      <head>
        <script src="jquery-1.8.3.min.js"></script>
        <script src="popup.js"></script>
        <style>
          body { width: 300px; }
          textarea { width: 250px; height: 100px;}
        </style>
      </head>
      <body>
        <textarea id="text"> </textarea>
        <button id="paste">Paste Selection</button>
      </body>
    </html>
    

    popup.js (so as to not have any inline code)

    $(function(){
      $('#paste').click(function(){pasteSelection();});
    });
    function pasteSelection() {
      chrome.tabs.query({active:true, windowId: chrome.windows.WINDOW_ID_CURRENT}, 
      function(tab) {
        chrome.tabs.sendMessage(tab[0].id, {method: "getSelection"}, 
        function(response){
          var text = document.getElementById('text'); 
          text.innerHTML = response.data;
        });
      });
    }
    

    selection.js

    chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
      if (request.method == "getSelection")
        sendResponse({data: window.getSelection().toString()});
      else
        sendResponse({}); // snub them.
    });
    

    manifest.json

    {
     "name": "Selected Text",
     "version": "0.1",
     "description": "Selected Text",
     "manifest_version": 2,
     "browser_action": {
       "default_title": "Selected Text",
       "default_icon": "online.png",
       "default_popup": "popup.html" 
     },
     "permissions": [
       "tabs",
       "<all_urls>"
     ],
     "content_scripts": [
       {
         "matches": ["<all_urls>"],
         "js": ["selection.js"],
         "run_at": "document_start",
         "all_frames": true
       }
     ]
    }
    

    Here is a link to source files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spent several hours with this SQL problem, which I thought would be
I have spent the last several hours trying to simply post the data (text/html)
To begin, Ive spent several hours looking for an answer and have come CLOSE
I have spent several hours today reading up on doing Custom Routing in ASP.NET
I have now spent several hours trying to figure this out. I have this
I have spent several hours on this, and I have made very little to
I have spent the last several hours trying to get this to work and
I have spent several hours on this, and tried various things. I can confirm
I have spent the last several hours scouring the internet looking for examples and
I suspect this is a very minor issue, but I have spent several hours

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.