30,js选中内容即复制

选中我就复制了![选中后直接放到粘贴板里,不信试试看]!


js

document.onclick = function() {

    if (window.getSelection) {

        text = window.getSelection();

    } else if (document.selection) {

        text = document.selection.createRange();

    }

    // 放到粘贴板里,操作浏览器自身的API

    // console.log(text.toString());

    document.execCommand('Copy'); // 执行浏览器的复制命令

}

你可能感兴趣的:(30,js选中内容即复制)