How to add Copy to clipboard functionality in ExtJs?

*爱你&永不变心* 提交于 2020-01-11 10:28:14

问题


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.



来源:https://stackoverflow.com/questions/5164001/how-to-add-copy-to-clipboard-functionality-in-extjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!