简体   繁体   中英

Pasting text from clipboard to Firefox and Chrome

I am using this function that pastes text from clipboard into multiple text fields.

function pasteFromClipboard(className) {
        var data = window.clipboardData.getData('Text');
        if (data != null) {
            var cells = data.split('\n');
            var columns = $$('.'+className);

            for (i = 0; i < cells.length; i++) {
                if ( columns[i] != undefined ){
                    columns[i].value = cells[i];   
                }
            }
        }
    }

This stuff that is attached to button via "onClick" works in IE, but not in FF or Chrome. Now I know FF restricts access to clip, but I have manipulated the values in preferences with no success.

Can anyone help me out with this functionality, so it would work in Chrome? Is there a window.clipboardData.getData('Text'); similar option to make it work in FF and Chrome?

OK. So I gave up on this some time ago. I just created an additional textarea control, where I paste my stuff into.

Actions on page then read this control and do the work - then delete the content in this control.

Some would say its a clumsy solution, but i prefer "old fashion" and safe.

Best regards, no9.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM