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 1101091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:59:01+00:00 2026-05-17T00:59:01+00:00

In my popup.html in my chrome extension I have a button that will get

  • 0

In my popup.html in my chrome extension I have a button that will get the selected text in de webpage and put it in my textarea in the popup.html.

  1. First I select text in a webpage
  2. I click on my extension. An popup will show with a textarea and a button.
  3. When I Push the button the selected text will show in my textarea.

is someone who can help me with this issue,

Thanks,

Wouter

  • 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-05-17T00:59:01+00:00Added an answer on May 17, 2026 at 12:59 am

    If you want to implement that, you would need to use a couple of API’s.

    You need to make sure of Content Scripts in order to capture selection within the DOM. Then you need to use Message Passing to let the Popup communicate to the Content Script. After you do all that, you can simply use chrome.tabs.sendRequest to send a message to the Content Script so that you get back a response with the data.

    For example, this is how you can do a Popup that fetches the current selection:

    popup.html

    <!DOCTYPE html> 
    <html>
    <head>
    <style>
      body { width: 300px; }
      textarea { width: 250px; height: 100px;}
    </style>
    <script>
    function pasteSelection() {
      chrome.tabs.getSelected(null, function(tab) {
        chrome.tabs.sendRequest(tab.id, {method: "getSelection"}, function (response) {
          var text = document.getElementById('text'); 
          text.innerHTML = response.data;
        });
      });
    }
    </script>
    </head>
    <body>
    <textarea id="text"> </textarea>
    <button onclick="pasteSelection(); ">Paste Selection</button>
    </body>
    </html>
    

    selection.js

    chrome.extension.onRequest.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",
     "browser_action": {
       "default_title": "Selected Text",
       "default_icon": "online.png",
       "default_popup": "popup.html" 
     },
     "permissions": [
       "tabs",
       "chrome://favicon/",
       "http://*/*", 
       "https://*/*"
     ],
     "content_scripts": [
      {
        "matches": ["http://*/*"],
        "js": ["selection.js"],
        "run_at": "document_start",
        "all_frames": true
      }
     ]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this chrome extension that shows some content in the popup.html. As the
I am making a chrome extension and I have a popup.html page that contains
I am currently writing a chrome extension so that I have a button on
Happy new year :) I have a Chrome extension which is a popup that
I'm working on a Google Chrome extension. In the popup I have the following
I want to implement an extension in Chrome that I'd display some text related
I'm making a Chrome Extension and need to view the HTML/CSS/JS of the popup.html
I have a simple javascript form in a chrome extension popup. When clicking the
I have a Chrome extension with a pageAction button. The user clicks on it
In background.html of my chrome extension I have: $(document).ready(function(){ var some_variable = some_variable; function

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.