Firefox addon sdk: how to copy textbox value from popup html to clipboard?

I am using Firefox addon-sdk to create add-ons for the Firefox browser.

I need to copy text from a text element to the clipboard in the popup.html file. I do not 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 the popup.js file:

$(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 this?

+4
source share
1 answer

First you need to get the textarea value using the contents of the script panel , then use message passing to pass this to the -on append, then use "clipboard" to save that value to the clipboard.

0

All Articles