4

I'm using Firefox's addon-sdk to create addons for Firefox browser.

I need to copy text from textbox element to clipboard in popup.html file. I don't want to use flash to copy text to the clipboard.

popup.html

<html>
<head>
<meta charset="utf-8"/>

<script src="jquery.min.js"></script> <!-- Including jQuery -->
<script type="text/javascript" src="const.js"></script> 
<script type="text/javascript" src="popup.js"></script>

<script>


</script>
</head>
<body style="font-family:Tahoma, Geneva, sans-serif;line-height:30px;width:250px;">
<form >


    element Id : <input type="button" onclick="copy($('#idElem').val())" class="btn" value="copy"/>
<input type="text" id="idElem" value=""/><br/>
element class name : &nbsp;&nbsp;&nbsp; <input type="button" class="btn" onclick="copy($('#classNameElem').val())" value="copy"/>
<input type="text" id="classNameElem" value=""/><br/>
element xpath : &nbsp;&nbsp;&nbsp; <input type="button" onclick="copy($('#xpathElem').val())" class="btn" value="copy"/>
<input type="text" id="xpathElem" value=""/><br/>



</form>

</body>
</html>

And popup.js file is :

$(document).ready(function () {
    addon.port.on("vars",  function(vars) {
        if (vars){
          $("#idElem").val(vars[0]);
      $("#classNameElem").val(vars[1]); 
      $("#xpathElem").val(vars[2]);
    }
    });
});

How can I do it?

Lucky
  • 16,787
  • 19
  • 117
  • 151
Saeed Ghareh Daghi
  • 1,164
  • 1
  • 13
  • 21
  • Here are some topics on clipboard usage in firefox: https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/clipboard and http://stackoverflow.com/questions/26545871/paste-data-from-clipboard-using-document-execcommandpaste-within-firefox-ex/26554409#26554409 and http://stackoverflow.com/questions/27866328/copy-to-clipboard-in-firefox-extension-not-working – Noitidart May 30 '15 at 09:38

1 Answers1

0

You'll first have to get the textarea value with a panel content script, then use message passing to pass that to the add-on process, then use the "clipboard" module to save that value to the clipboard.

erikvold
  • 15,988
  • 11
  • 54
  • 98