JavaScript禁止頁(yè)面操作的示例代碼
單的JS禁止頁(yè)面右鍵菜單--避免網(wǎng)站信息被盜用
<script type="text/javascript">
function block(oEvent){
if(window.event)
oEvent=window.event;
if(oEvent.button==2)
alert("鼠標(biāo)右鍵不可用");
}
document.onmousedown=block;
</script>
網(wǎng)頁(yè)上禁止復(fù)制主要靠JavaScript來(lái)實(shí)現(xiàn)。
<BODY oncontextmenu="return false" onselectstart="return false"
ondragstart="return false" onbeforecopy="return false" oncopy=document.selection.empty() onselect=document.selection.empty()>
-----------------------------------------------
防止復(fù)制的js
-----------------------------------------------
<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>
-------------------------------------------------------
防止下載的js
-------------------------------------------------------
<noscript><iframe src=""></iframe></noscript>
--------------------------------------------------------
下面是防止右鍵的js:
<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禁止選擇和復(fù)制</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>
這里是網(wǎng)頁(yè)內(nèi)容,試試您能不能復(fù)制?
</body>
</html>
應(yīng)用實(shí)例:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>JS控制頁(yè)面</title>
<script language="javascript" type="text/javascript">
//禁止用戶使用郵件(隱藏右鍵菜單)
document.oncontextmenu = function forbidRightKey() {
window.event.returnValue = false;
}
//禁止用戶使用郵件(提示用戶禁用右鍵)
function block() {
var oEvent;
if (window.event)
oEvent = window.event;
if (oEvent.button == 2)
alert("鼠標(biāo)右鍵不可用");
}
document.onmousedown = block;
//當(dāng)用戶按鍵AltF4的時(shí)候,提示關(guān)閉窗口信息
function altF4() {
if (window.event.altKey && window.event.keyCode == 115) {
window.close();
}
}
//alt 鼠標(biāo)左鍵 組成快捷鍵 選中文本框中內(nèi)容 調(diào)用方式<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 = "輸入搜索條件";
}
//禁用鍵盤(pán)上的某幾個(gè)鍵 調(diào)用onkeydown="ForbidKeys();"
function ForbidKeys() {
var content = window.event.keyCode;
if (content >= 65 && content <= 68) {
window.event.returnValue = false;
} else {
window.alert(content);
}
}
//禁止復(fù)制網(wǎng)頁(yè)內(nèi)容 <body oncopy="forbidCopy();">
function forbidCopy() {
window.event.returnValue = false;
window.clipboardData.setData("Text", "");
alert("禁止復(fù)制網(wǎng)頁(yè)內(nèi)容!");
}
//設(shè)置復(fù)制內(nèi)容 附加 本網(wǎng)站的URL
function SetCopyContent() {
window.event.returnValue = false;
var content = document.title + "/r/n";
content += document.getElementById("txt1").value + "/r/n";
content += "本資源來(lái)自 " + this.location.href;
window.clipboardData.setData('Text', content);
alert("復(fù)制成功,請(qǐng)粘貼到你的QQ/MSN上推薦給你的好友");
}
//禁止刷新F5 和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;
//屏蔽JS錯(cuò)誤
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="復(fù)制文本框中的值" onclick="SetCopyContent();" />
<input id="txtContent" value="輸入搜索條件" style="color:Aqua" onclick="clearTxtByInput();" onblur="FillTxtByInput();" />
<p>content</p>
</div>
</form>
</body>
</html>
相關(guān)文章
JavaScript中檢測(cè)數(shù)據(jù)類(lèi)型的四種方法總結(jié)
這篇文章主要為大家詳細(xì)介紹了四個(gè)JavaScript中檢測(cè)數(shù)據(jù)類(lèi)型的常用方法,文中的示例代碼講解詳細(xì),具有一定的參考價(jià)值,需要的可以參考一下2023-04-04
微信小程序 wx.getUserInfo引導(dǎo)用戶授權(quán)問(wèn)題實(shí)例分析
這篇文章主要介紹了微信小程序 wx.getUserInfo引導(dǎo)用戶授權(quán)問(wèn)題,結(jié)合實(shí)例形式分析了微信小程序使用wx.getUserInfo引導(dǎo)用戶授權(quán)問(wèn)題的具體操作步驟與實(shí)現(xiàn)方法,需要的朋友可以參考下2020-03-03
通過(guò)javascript設(shè)置css屬性的代碼
通過(guò)javascript設(shè)置css屬性的方法需要的朋友可以參考下。2009-12-12
JS簡(jiǎn)單獲得節(jié)點(diǎn)元素的方法示例
這篇文章主要介紹了JS簡(jiǎn)單獲得節(jié)點(diǎn)元素的方法,結(jié)合實(shí)例形式分析了javascript獲取頁(yè)面節(jié)點(diǎn)元素及修改元素屬性相關(guān)操作技巧,需要的朋友可以參考下2018-02-02
JavaScript中window.open用法實(shí)例詳解
這篇文章主要介紹了JavaScript中window.open用法,實(shí)例分析了window.open方法的功能、參數(shù)及使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-04-04

