Skip to content Skip to sidebar Skip to footer

Firefox Webextension Not Copying To Clipboard

I have a Firefox web extension which is supposed to generate buttons which copy a link to the clipboard. In my content script for the plugin, I have: button.onclick = function

Solution 1:

You have to append txtToCopy to the DOM to copy from it and it has to be "visible" (more or less).

button.onclick = function() {
    var link = window.location.href.replace(/#[0-9a-zA-Z_]+$/, '') + '#' + id;
    var txtToCopy = document.createElement('input');
    txtToCopy.style.left = '-300px';
    txtToCopy.style.position = 'absolute';
    txtToCopy.value = link;
    document.body.appendChild(txtToCopy);
    txtToCopy.select();

    console.log(txtToCopy.value);
    var res = document.execCommand('copy');
    console.log(res);

    txtToCopy.parentNode.removeChild(txtToCopy);

}

Post a Comment for "Firefox Webextension Not Copying To Clipboard"