javascript右键菜单设置

DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>title>
		<script language="javascript" src="shijian.js">script>
	head>
	<body>
		<div id="mydiv">tight click or Ctrl+click me to get a custom content menu.
		Click anywhere else to get the default context menu.
		div>
		<ul id="myMenu" style="position:absolute;visibility:hidden;background-color: silver;">
			<li><a href="http://www.xxx.cn">新官网a>li>
			<li><a href="http://www.xxxx.com">老官网a>li>
			<li><a href="http://www.xxxxx.com">王之王a>li>
		ul>
		<script language="javascript">
		 window.onload=function(event){
			 var div=document.getElementById('mydiv');
			 div.addEventListener('contextmenu',function(event){
				 event=event||window.event;
				 event.preventDefault();    //取消默认
				 var menu=document.getElementById('myMenu');
				 menu.style.left=event.pageX+"px";
				 menu.style.top=event.pageY+"px";
				 menu.style.visibility="visible";
			 });
			 document.addEventListener('click',function(event){
				 document.getElementById('myMenu').style.visibility="hidden";
			 });
		 };
		 window.onbeforeunload=function(event){
			 event=event||window.event;
			 var m="你将离开此页";
			 event.returnValue=m;
			 event.preventDefault(m);
			 return m;
		 };
		script>
		
	body>
html>

你可能感兴趣的:(javascript学习日记,javascript)