0

I made an extension where I can copy a text clicking a button. However, it doesn´t work...

manifest.js:

{
    "manifest_version": 2,
    "name": "Copy",
    "description": "Copy",
    "version": "1.0",
    "browser_action":{
        "default_popup": "popup.html",
        "default_title": "Copy"
    },
"content_scripts": [ {
  "matches": ["http://www.google.com/*"],
  "js": ["popup.js"]
} ],
    "permissions": ["tabs","clipboardWrite","clipboardRead"]
}

popup.html:

<script src='popup.js'></script>

<button onclick="copyToClipboard()">Copy text</button>

popup.js:

function copyToClipboard() {
  var $temp = $("<input>");
  $("body").append($temp);
  $temp.val("this is a text").select();
  document.execCommand("copy");
  $temp.remove();
}

Any idea what's wrong?

  • Can you provide more info on what doesn't work? Does it not create the input? Does it not set the input text? Does it not copy the text to the clipboard? – Matt Zeunert Mar 04 '18 at 04:50
  • Do you have access to jQuery within your extension? – William Fleming Mar 04 '18 at 04:50
  • Possible duplicate of [onClick within Chrome Extension not working](https://stackoverflow.com/questions/13591983/onclick-within-chrome-extension-not-working) – wOxxOm Mar 04 '18 at 08:45

0 Answers0