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>