js获取网页复制内容

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_28543437/article/details/52469819
/**
 * 获取网页复制动作
 * oncopy="getCopyLog(this,position)"
 * @param string text
 */
function getCopyLog(res,position){
//<script type="text/javascript" src="public/zt/zt.js"></script>
if(window.getSelection){
var thisVal = window.getSelection();
}else{
var thisVal = document.selection.createRange().text;
}
var res = $(res).text();
var res = $.trim(res);
    if(res != $.trim(thisVal))return;
    
    var position = $.trim(position);
    var pre = window.location.pathname;
    pre = pre.match(/^\/zt-([a-zA-Z0-9_]+)(\.html|\s*|\.html?.*|\.\s*|\.h\s*|\.ht\s*|\.htm\s*)$/);
    pre = pre[0];
    if(pre.indexOf('.') != -1){
    pre = pre.split('.');
    pre = pre[0];
    }
    pre = pre + '.html';
var host = window.location.host+pre;
var url = '/special/getCopyLog';
$.post(url,{'position':position,'host':host},function(res){
if(res.code == 0)return true;
else alert('数据保存失败');
})
}

没有更多推荐了,返回首页