标签:des style blog http java 使用 os io
今天在看http://www.yu1u.org/3419.html这里的网页的时候发现,这里的文字图片不能直接复制,鼠标右键没有反应,经简单查看,可以发现限制这些功能的代码大致如下:
document.body.oncontextmenu=function(){return false;}; document.body.ondragstart=function(){return false;}; document.body.onselectstart=function(){return false;}; document.body.onbeforecopy=function(){return false;}; document.body.onselect=function(){document.selection.empty();}; document.body.oncopy=function(){document.selection.empty();};
其关键性的代码为:
document.body.oncopy = function() { var CurUserNameCookiescgcg = getCookie("LoginName"); if (CurUserNameCookiescgcg == "" || CurUserNameCookiescgcg == null) { var docarttitle = document.getElementById("docarttitle"); var docencodetitle = ""; if (docarttitle == null) { docencodetitle = "" } else { docencodetitle = "&titleencode=" + docarttitle.value } $.ajax({ url: "http://www.360doc.com/ajax/GetLoginForm20130912.ashx?ArtID=" + ArticleID + "&type=2&arttype=" + CurArtType + docencodetitle, cache: false, success: function(result) { $("#LayerLogin").html(result); showBg("dialog", "dialog_content", "1") }, error: onFailed }); return false } else { var selhtml = ""; var selection; if (window.getSelection) { selection = window.getSelection(); if (selection != null) { selhtml = selection.toString() } } else if (document.selection) { selection = document.selection.createRange(); if (selection != null) { selhtml = selection.text } } if (selhtml.length > 200) { document.getElementById('fuzhitishidiv').style.display = 'none'; if (getCookie("360doc1") != null && UserID != 0) { $.ajax({ url: "http://www.360doc.com/ajax/GetLoginForm20130912.ashx?ArtID=" + ArticleID + "&type=5&arttype=" + CurArtType + "", cache: false, success: function(result) { if (result == "-1") { return true } else { if (document.getElementById("fuzhitishidiv") != null) { document.getElementById("fuzhitishidiv").innerHTML = "<div style=\"position: absolute; z-index: 2001;\" ><img src=\"http://pubimage.360doc.com/wz/tuanceng.gif\" usemap=\"#Map2\" /><map name=\"Map2\" id=\"Map2\"><area shape=\"rect\" coords=\"288,23,307,42\" href=\"javascript:void(0);\" onclick=\"document.getElementById('fuzhitishidiv').innerHTML='';document.getElementById('fuzhitishidiv').style.display='none';\" /></map></div>"; window.scroll(0, 0); document.getElementById("fuzhitishidiv").style.display = '' } else { alert("提示:点击标题下方的“转藏到我的图书馆”,将文章保存到您的个人图书馆中,然后可以拷贝文章的内容!") } return false } }, error: onFailed }) } else { if (document.getElementById("fuzhitishidiv") != null) { document.getElementById("fuzhitishidiv").innerHTML = "<div style=\"position: absolute; z-index: 2001;\" ><img src=\"http://pubimage.360doc.com/wz/tuanceng.gif\" usemap=\"#Map2\" /><map name=\"Map2\" id=\"Map2\"><area shape=\"rect\" coords=\"288,23,307,42\" href=\"javascript:void(0);\" onclick=\"document.getElementById('fuzhitishidiv').innerHTML='';document.getElementById('fuzhitishidiv').style.display='none';\" /></map></div>"; window.scroll(0, 0); document.getElementById("fuzhitishidiv").style.display = '' } else { alert("提示:点击标题下方的“转藏到我的图书馆”,将文章保存到您的个人图书馆中,然后可以拷贝文章的内容!") } return false } } else { return true } } }
一、把这些代码或者外部js链接给去掉,但是这样做根本不现实:
同样由于以上的原理2,同样不能奏效;
三、开发Chrome插件+API HOOK实现
插件制作流程:此方法看来是最有效的了;
代码:
manifest.json
{ "name": "UBC", "manifest_version": 2, "version": "1.0.0", "description": "UnBlock Copy", "browser_action": { "default_icon": "icon.png", "default_title": "UnBlock Copy", "default_popup": "popup.html" }, "content_scripts": [{ "matches": ["http://*/*","https://*/*"], "js": ["js/hookapi.js"], "run_at": "document_end", "all_frames": true }] }
"manifest_version": 2,
这一行固定,新的Chrome插件开发规范,网上的大多数教程没有此行。
popup.html
<div style="width:200px;"> <center><img src="icon.png"/></center> <ol> <li>Unblock Copy Event</li> <li>Unblock Paste Event</li> <li>Unblock Select Event</li> </ol> </div>
//UnHook Copy Related Events var arr_hook_event = ["oncontextmenu","ondragstart","onselectstart","onselect","onbeforecopy","oncopy"]; function Array_indexOf(arr,item) { for(var i = 0;i<arr.length;i++) { if(arr[i] == item) { return i; } } return -1; } function UnHookEvent(onevent) { var _event = onevent.substr(2); document.addEventListener(_event, function(e) { e.stopPropagation(); }, true); } for (var k in document.body) { if (/^on/.test(k)) { var __index = Array_indexOf(arr_hook_event,k); if(__index!= -1) { UnHookEvent(k); } } }
标签:des style blog http java 使用 os io
原文地址:http://blog.csdn.net/agoago_2009/article/details/38686717