Single JS prohibits page right-click menu - to prevent website information from being stolen
Copy the code code as follows:
<script type="text/javascript">
function block(oEvent){
if(window.event)
oEvent=window.event;
if(oEvent.button==2)
alert("The right mouse button is not available");
}
document.onmousedown=block;
</script>
The prohibition of copying on web pages is mainly implemented through JavaScript.
<BODY oncontextmenu="return false" onselectstart="return false"
ondragstart="return false" onbeforecopy="return false" oncopy=document.selection.empty() onselect=document.selection.empty()>
--------------------------------------------------
Prevent copying js
--------------------------------------------------
Copy the code code as follows:
<SCRIPT language=JavaScript1.2>
function disableselect(e){
return false}
function reEnable(){return true
}
file://if IE4+
document.onselectstart=new Function ("return false")
file://if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</SCRIPT>
<SCRIPT language=JavaScript type=text/JavaScript>
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</SCRIPT>
-------------------------------------------------- -----
Prevent downloading js
-------------------------------------------------- -----
<noscript><iframe src=""></iframe></noscript>
-------------------------------------------------- ------
The following is the js to prevent right-clicking:
Copy the code code as follows:
<script language="JavaScript">
<!--
if (window.Event)
document.captureEvents(Event.MOUSEUP);
function nocontextmenu() {
event.cancelBubble = true
event.returnValue = false;
return false;
}
function norightclick(e) {
if (window.Event){
if (e.which == 2 || e.which == 3)
return false;
}else{
if (event.button == 2 || event.button == 3){
event.cancelBubble = true
event.returnValue = false;
return false;
}
}
}
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
//-->
</script>
<title>CSS prohibits selection and copying</title>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
<style>
body{
-moz-user-select:none;
hutia:expression(this.onselectstart=function(){return(false)});
}
</style>
</head>
<body>
Here is the content of the web page. Can you copy it?
</body>
</html>
Application examples:
Copy the code code as follows:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>JS control page</title>
<script language="javascript" type="text/javascript">
//Prohibit users from using mail (hide right-click menu)
document.oncontextmenu = function forbidRightKey() {
window.event.returnValue = false;
}
//Prohibit users from using mail (prompts users to disable right-clicking)
function block() {
var oEvent;
if(window.event)
oEvent = window.event;
if (oEvent.button == 2)
alert("The right mouse button is not available");
}
document.onmousedown = block;
//When the user presses AltF4, prompt to close the window information
function altF4() {
if (window.event.altKey && window.event.keyCode == 115) {
window.close();
}
}
//Alt left mouse button forms a shortcut key to select the content in the text box. Calling method <body onkeydown="altF4();" >
function getTxtSelect(eventControl) {
if (eventControl.altKey) {
document.getElementById("txt1").select();
}
}
function clearTxtByInput() {
document.getElementById("txtContent").value = "";
}
function FillTxtByInput() {
document.getElementById("txtContent").value = "Enter search criteria";
}
//Disable certain keys on the keyboard and call onkeydown="ForbidKeys();"
function ForbidKeys() {
var content = window.event.keyCode;
if (content >= 65 && content <= 68) {
window.event.returnValue = false;
} else {
window.alert(content);
}
}
//Forbid copying web content<body oncopy="forbidCopy();">
function forbidCopy() {
window.event.returnValue = false;
window.clipboardData.setData("Text", "");
alert("Copying of web content is prohibited!");
}
//Set the copied content and append the URL of this website
function SetCopyContent() {
window.event.returnValue = false;
var content = document.title + "/r/n";
content += document.getElementById("txt1").value + "/r/n";
content += "This resource comes from" + this.location.href;
window.clipboardData.setData('Text', content);
alert("Copied successfully, please paste it into your QQ/MSN and recommend it to your friends");
}
//Disable refreshing F5 and Ctrl+F5
function ForbidFreshPage() {
if ((window.event.ctrlKey && window.event.keyCode == 116) || window.event.keyCode == 116) {
window.event.keyCode = 0;
window.event.returnValue = false;
}
}
document.onkeydown = ForbidFreshPage;
//Shield JS errors
function killErrors() {
return true;
}
window.onerror = killErrors;
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="txt1" type="text" value="Hello World!" onclick="getTxtSelect(event)"/>
<input type="button" value="Copy the value in the text box" onclick="SetCopyContent();" />
<input id="txtContent" value="Enter search criteria" style="color:Aqua" onclick="clearTxtByInput();" onblur="FillTxtByInput();" />
<p>content</p>
</div>
</form>
</body>
</html>