DOM中对象的属性
event.button為1為左鍵,2為右鍵,3為左右鍵按同事按(IE瀏覽器好像不行,火狐的可以)
<body οnmοusedοwn="if(event.button == 2){alert('禁止復(fù)制')}">
<input type="button" value="當(dāng)前頁(yè)面地址" οnclick="alert(location.href)" />
<input type="button" value="重定向地址" οnclick="location.href='8.html'" /> 和navigate方法效果一樣
window.location.reload() 刷新當(dāng)前頁(yè)面
<input type="button" value="點(diǎn)擊" οnclick="if(window.event.ctrlKey){alert('按下了Ctrl')}else{alert('普通點(diǎn)擊')}" />
IE瀏覽器可以,火狐的不行
window.event 用來(lái)獲取發(fā)生時(shí)間時(shí)的信息,時(shí)間不局限于window對(duì)象的事件,所有的元素時(shí)間都可以
通過(guò)event屬性去到相關(guān)信息
window.event中的clientX clientY發(fā)生時(shí)間時(shí)鼠標(biāo)在客戶(hù)區(qū)的坐標(biāo)
screenX screenY發(fā)生時(shí)間時(shí)鼠標(biāo)在屏幕上的坐標(biāo)
offsetX? offsetY發(fā)生時(shí)間時(shí)鼠標(biāo)相對(duì)于事件源(比如點(diǎn)擊按鈕時(shí)出發(fā)的onclick)的坐標(biāo)
returmValue事件,如果將returnValue設(shè)置為false,就會(huì)取消默認(rèn)時(shí)間的處理,比如禁止超鏈接的onclick里面禁止訪(fǎng)問(wèn)href的頁(yè)面,在表單校驗(yàn)時(shí)禁止提交表單到服務(wù)器(本人測(cè)試,在IE下可以正常使用,火狐下不行不能執(zhí)行window.event.returnValue=false;,即禁止跳轉(zhuǎn)到百度頁(yè)面)
<a href="http://www.baidu.com" οnclick="alert('禁止訪(fǎng)問(wèn)');window.event.returnValue=false;">百度</a>
?
?
------------------------------------------------全部代碼--------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>演示文檔 -當(dāng)前頁(yè)面地址</title>
</head>
<body οnmοusedοwn="if(event.button == 2){alert('禁止復(fù)制')}">
<input type="button" value="當(dāng)前頁(yè)面地址" οnclick="alert(location.href)" />
<input type="button" value="重定向地址" οnclick="location.href='8.html'" />
<input type="button" value="點(diǎn)擊" οnclick="if(window.event.ctrlKey){alert('按下了Ctrl')}else{alert('普通點(diǎn)擊')}" />
<a href="http://www.baidu.com" οnclick="alert('禁止訪(fǎng)問(wèn)');window.event.returnValue=false;">百度</a>
</body>
</html>
?
總結(jié)
- 上一篇: DOM中的onbeforeunload函
- 下一篇: DOM中的navigate()函数