DOM中对象的属性
event.button為1為左鍵,2為右鍵,3為左右鍵按同事按(IE瀏覽器好像不行,火狐的可以)
<body οnmοusedοwn="if(event.button == 2){alert('禁止復制')}">
<input type="button" value="當前頁面地址" οnclick="alert(location.href)" />
<input type="button" value="重定向地址" οnclick="location.href='8.html'" /> 和navigate方法效果一樣
window.location.reload() 刷新當前頁面
<input type="button" value="點擊" οnclick="if(window.event.ctrlKey){alert('按下了Ctrl')}else{alert('普通點擊')}" />
IE瀏覽器可以,火狐的不行
window.event 用來獲取發生時間時的信息,時間不局限于window對象的事件,所有的元素時間都可以
通過event屬性去到相關信息
window.event中的clientX clientY發生時間時鼠標在客戶區的坐標
screenX screenY發生時間時鼠標在屏幕上的坐標
offsetX? offsetY發生時間時鼠標相對于事件源(比如點擊按鈕時出發的onclick)的坐標
returmValue事件,如果將returnValue設置為false,就會取消默認時間的處理,比如禁止超鏈接的onclick里面禁止訪問href的頁面,在表單校驗時禁止提交表單到服務器(本人測試,在IE下可以正常使用,火狐下不行不能執行window.event.returnValue=false;,即禁止跳轉到百度頁面)
<a href="http://www.baidu.com" οnclick="alert('禁止訪問');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>演示文檔 -當前頁面地址</title>
</head>
<body οnmοusedοwn="if(event.button == 2){alert('禁止復制')}">
<input type="button" value="當前頁面地址" οnclick="alert(location.href)" />
<input type="button" value="重定向地址" οnclick="location.href='8.html'" />
<input type="button" value="點擊" οnclick="if(window.event.ctrlKey){alert('按下了Ctrl')}else{alert('普通點擊')}" />
<a href="http://www.baidu.com" οnclick="alert('禁止訪問');window.event.returnValue=false;">百度</a>
</body>
</html>
?
總結
- 上一篇: DOM中的onbeforeunload函
- 下一篇: DOM中的navigate()函数