How to add Copy to clipboard functionality in ExtJ

2019-02-26 02:15发布

问题:

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);
}

回答1:

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 combination of Flash and JavaScript. Zero Clipboard is one way.