javascript - How to add Copy to clipboard functionality in ExtJs? - Stack Overflow

admin2025-04-20  0

How to add Copy to clipboard functionality in ExtJs? It's working fine with IE browser but not Firefox, What else has to be altered to make it work in FF browser.

Code:

function selectCopy(txt,txtId)
{
    Ext.getCmp(txtId).focus();

    Ext.getCmp(txtId).selectText();

    var s = document.getElementById(txtId).value;

    var div = document.createElement('div');
    div.innerText = '"' + s + '"';
    document.body.appendChild(div);

    if (window.clipboardData  && clipboardData.setData){
        window.clipboardData.setData('text', s);}
    else
        return (s);
}

How to add Copy to clipboard functionality in ExtJs? It's working fine with IE browser but not Firefox, What else has to be altered to make it work in FF browser.

Code:

function selectCopy(txt,txtId)
{
    Ext.getCmp(txtId).focus();

    Ext.getCmp(txtId).selectText();

    var s = document.getElementById(txtId).value;

    var div = document.createElement('div');
    div.innerText = '"' + s + '"';
    document.body.appendChild(div);

    if (window.clipboardData  && clipboardData.setData){
        window.clipboardData.setData('text', s);}
    else
        return (s);
}
Share Improve this question edited Nov 12, 2014 at 18:37 abatishchev 100k88 gold badges301 silver badges442 bronze badges asked Mar 2, 2011 at 6:05 samplesample 612 gold badges4 silver badges6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Answer: Firefox has to be altered. It cannot be done with JavaScript alone.

Clipboard access in the browser is considered a security risk. See this page for an explanation.

That said, you can achieve this with a bination of Flash and JavaScript. Zero Clipboard is one way.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745158684a288009.html

最新回复(0)