R
R
ramazan2016-04-06 16:59:52
JavaScript
ramazan, 2016-04-06 16:59:52

How to pass the text selected in the tab to popup.html?

So far, I can only display the value of the variable from popup.js in popup.html.
popup.html:

<!DOCTYPE html>
<html>
  <head>
    <title>Расширение</title>
  </head>  
  <body>		
  <button>
    <script src="popup.js"></script>		
  </button>
  </body>  
</html>

manifest.json:
{
  "name": "Расширение",
  "version": "0.1",
  "manifest_version": 2,
 ],
  "permissions": [
  		"tabs",         
  		"http://*/",
        "https://*/"
        ],
  "icons": {
    "32": "magnifier.png"
  },
"browser_action": {
        "default_title": "Расширение",
        "default_icon" : "magnifier.png",
        "default_popup": "popup.html"
        }
}

popup.js:
var result = "Hello"
document.write(result);

or display the selected text in an alert. popup.js:
chrome.tabs.executeScript( {
  code: "alert(document.getSelection().toString());"
});

But I can figure out how to pass the value of document.getSelection().toString() to popup.html.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
russbog, 2016-04-10
@russbog

It's not entirely clear what needs to be done.
As far as I understand, you need to display the text selected on the page in a pop-window.
dig this way

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question