最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览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.

发布评论

评论列表(0)

  1. 暂无评论