<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>自定义鼠标右键弹出式菜单</title>
<style type="text/css">
<!–
.div1 { border-top:buttonface 1px solid;border-left:buttonface 1px solid;border-bottom:windowframe 1px solid;border-right:windowframe 1px solid;}
.div2 { border-top:window 1px solid;border-left:window 1px solid;border-bottom:buttonshadow 1px solid;border-right:buttonshadow 1px solid;}
.mouseover {background-color:highlight;color:highlighttext;font-size: 12px;cursor:hand;font-size: 12px;}
.mouseout {background-color:buttonface;color:buttontext;font-size: 12px;cursor:default;font-size: 12px;}
–>
</style>
<script language="javascript">
function popupmouserightbuttonupmenu()
{
if(mousemenu.style.visibility==visible) mousemenu.style.visibility=hidden;
if (event.srcelement.tagname==a || event.srcelement.tagname==textarea || event.srcelement.tagname==input || document.selection.type!=none)
return true;
else
{
if (event.clientx+150 > document.body.clientwidth) mousemenu.style.left=event.clientx+document.body.scrollleft-150;
else mousemenu.style.left=event.clientx+document.body.scrollleft;
if (event.clienty+divh > document.body.clientheight) mousemenu.style.top=event.clienty+document.body.scrolltop-divh;
else mousemenu.style.top=event.clienty+document.body.scrolltop;
mousemenu.style.visibility=visible;
}
return false;
}
function drawmouserightbuttonupmenu(){
divh=2;
//oselection = document.selection;
var hrstr=<tr><td align=\"center\" valign=\"middle\" height=\"2\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"128\" height=\"2\"><tr><td height=\"1\" bgcolor=\"buttonshadow\"><\/td><\/tr><tr><td height=\"1\" bgcolor=\"buttonhighlight\"><\/td><\/tr><\/table><\/td><\/tr>;
var menuitemstr1=<tr><td align=\"center\" valign=\"middle\" height=\"20\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"132\"><tr><td valign=\"middle\" height=\"16\" class=\"mouseout\" onmouseover=\"this.classname=\mouseover\\" onmouseout=\"this.classname=\mouseout\\" onclick=\"
var menuitemstr2="<\/td><\/tr><\/table><\/td><\/tr>";
var historymenu=[window.history.back()\">后退,window.history.forward()\">前进];
var sysmenu=[\">查找 <input type=\"text\" size=\"10\" onkeypress=\"if (event.keycode == 13) {mousemenu.style.visibility=\hidden\;var temp = this.value; this.value = \\;return findinpage(temp)}\";\>,
document.execcommand(\selectall\)\">全选,
mousemenu.style.visibility=\hidden\;document.execcommand(\saveas\,\true\)\">另存为 …,
location.replace(\view-source:\+location.href)\">查看源文件,
mousemenu.style.visibility=\hidden\;window.print()\">打印,
window.location.reload()\">刷新];
var menustr=;
for(i=0;i<historymenu.length;i++)
{
menustr+=menuitemstr1+historymenu[i]+menuitemstr2;
divh+=20;
}
menustr+=hrstr;
for(i=0;i<arguments.length;i++)
{
menustr+=menuitemstr1+arguments[i]+menuitemstr2;
divh+=20;
}
if(arguments.length>0)
{
menustr+=hrstr;
divh+=2;
}
for(i=0;i<sysmenu.length;i++)
{
menustr+=menuitemstr1+sysmenu[i]+menuitemstr2;
divh+=20;
}
var aboutmenu=[mousemenu.style.visibility=\hidden\;alert(\http:\/\/www.sina.com.cn\\nmailto:hhw_lb@263.net\)">关于 …]
menustr+=hrstr;
for(i=0;i<aboutmenu.length;i++)
{
menustr+=menuitemstr1+aboutmenu[i]+menuitemstr2;
divh+=20;
}
var menutop = <div id=\"mousemenu\" class=\"div1\" style=\"position:absolute; left:0px; top:0px; width=150;height=+divh+; z-index:1; visibility:hidden;\">\n +
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"div2\">\n +
<tr>\n +
<td bgcolor=\" + menubarcolor+ \" width=\"50\" valign=\"bottom\" align=\"center\" bgcolor=\"buttonface\">\n +
<\/td>\n+
<td bgcolor=\"buttonface\">\n+
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">;
var menubottom = <\/table><\/td><\/tr><\/table><\/div>;
document.write(menutop+menustr+menubottom);
//prompt(aa,menutop+menustr+menubottom)
document.body.oncontextmenu=new function(return popupmouserightbuttonupmenu(););
document.body.onclick=new function(if(event.srcelement.tagname !=\input\) mousemenu.style.visibility=\hidden\);
document.body.onscroll=new function(mousemenu.style.visibility=\hidden\;);
document.body.onselectstart=new function(mousemenu.style.visibility=\hidden\;);
window.onresizestart=new function(mousemenu.style.visibility=\hidden\;);
}
var ns4 = (document.layers);
var ie4 = (document.all);
var win = window;
var n = 0;
function findinpage(str) {
var txt, i, found;
if (str == )
return false;
if (ns4) {
if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;
if (n == 0)
alert(文档搜索完毕。);
}
if (ie4) {
txt = win.document.body.createtextrange();
for (i = 0; i <= n && (found = txt.findtext(str)) != false; i++) {
txt.movestart(character, 1);
txt.moveend(textedit);
}
if (found) {
txt.movestart(character, -1);
txt.findtext(str);
txt.select();
txt.scrollintoview();
n++;
}
else {
if (n > 0) {
n = 0;
findinpage(str);
}
else
alert(文档搜索完毕。);
}
}
return false;
}
</script>
</head>
<body>
自定义鼠标右键弹出式菜单
<script language="javascript">
<!–
var menubarcolor =#6600ff;
drawmouserightbuttonupmenu();
//–>
</script>
</body>
</html>
