javascript自定义右键菜单

<title>右键菜单v1.0</title>
<style>
body { font-family:Verdana;font-size:11px;background-color:#D6D3CE;}
#menu { position:absolute;border: 2px outset threedhighlight;background-color:inactiveborder;padding:2px;width:180px;visibility:hidden;}
.item { padding:2px;width:100%;cursor:default;border:1px solid inactiveborder;}
.item img { vertical-align:middle;margin-right:10px;}
.item span { visibility:hidden;width:21px;height:12px;}
.line { border-top:1px solid #848284;border-bottom:1px solid white;margin:2px;}
</style>
<body>
<SCRIPT LANGUAGE="JavaScript">
document.oncontextmenu = function() {showMenu();return false;}
document.onmouseup = function() {hiddenMenu();}
document.onselectstart = function() {return false;}
//system variable
var menuOpened = false;
//user variable
var oWhere = document.body;
var menu = document.createElement("div");
addItem("http://www.sayee.com/cloudchen/js/rightmenuimg/forward.gif","下一页","history.forward()",1);
addItem("http://www.sayee.com/cloudchen/js/rightmenuimg/back.gif","上一页","history.back()",1);
addItem("","刷新","history.go(0)",1);
addItem("","查看源文件","location.href='view-source:'+location.href",1);
addLine()
addItem("","我的主页","window.open('http://piggydesign.yeah.net')",1);
addItem("","我的网页日历","window.open('http://www.sayee.com/cloudchen/js/myCalendar.htm')",1);
addItem("","模拟列表框","window.open('http://www.sayee.com/cloudchen/js/simulation_select.htm')",1);
addLine()
addItem("","打印","window.print()",1);
addItem("","打印预览","document.all.WebBrowser.ExecWB(7,2)",1);
addLine()
addItem("","属性","document.all.WebBrowser.ExecWB(10,2)",1);
oWhere.appendChild(menu);
menu.id="menu";
menu.onmouseup = function() {event.cancelBubble=true;}
//addItem
function addItem(img,text,href,type) {
var item = document.createElement("div");
menu.appendChild(item);
if(img){item.innerHTML = "<img src="+img+">"}else{item.innerHTML = "<span></span>"};
if(text)item.innerHTML += text;
if(href)item.onmouseup = function() { clickGo(href,type)}
item.onmouseover = function() { mouseoverState(this)}
item.onmouseout = function() { mouseoutState(this)}
item.className="item";
}
function mouseoverState(obj) {
with(obj.style) {
border="1px solid #08246B";
backgroundColor="#9496AD"
}
}
function mouseoutState(obj) {
with(obj.style) {
border="1px solid inactiveborder";
backgroundColor="";
}
}
function clickGo(href,type) {
hiddenMenu();
switch(type) {
case 0:location.href=href;break;
case 1:javascript:eval(href);break;
}
}
//addLine
function addLine() {
line = document.createElement("div")
line.className = "line";
menu.appendChild(line);
}function showMenu() {
if(menuOpened) return false;
menuOpened = true;
var menu = document.all.menu;
with(menu.style) {
visibility="visible";
if(event.clientX+menu.offsetWidth>document.body.offsetWidth)
pixelLeft=event.clientX-menu.offsetWidth;
else
pixelLeft=event.clientX;
if(event.clientY+menu.offsetHeight>document.body.offsetHeight)
pixelTop=event.clientY-menu.offsetHeight;
else
pixelTop=event.clientY;
}

}
function hiddenMenu() {
if(!menuOpened) return false;
menuOpened = false;
var menu = document.all.menu;
with(menu.style) {
visibility="hidden";
}
}
</SCRIPT>
<object classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" id="WebBrowser" width="0" height="0">
</object>
自定义右键菜单v.10
<UL>
<LI>功能简单,使用方便
<LI>支持图片、链接、javascript函数
<LI>界面摹仿Acrobat Reader6.0
<LI>功能陆续完善中。。。
<LI>作者:cloudchen
<LI>创建日期:2003/8/25
</UL>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值