自定义 IE 鼠标右键弹出式

转载 2006年05月20日 19:56:00
 

<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.playyuer.com//nmailto:playyuer@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>

 

 

做一个类似于window右键的弹出式菜单。

直接下载js文件和观看效果: http://202.114.98.14/~cityhunter/jscripts/jscripts.htm
代码如下: 

var obj;

function loadobj(o)
{
  obj=o;
}

function expand()
{
  var h=parseInt(obj.height);
  var w=parseInt(obj.width);
  var op=10;

  if( h<=170 )
  {
    if( w<60 )
      obj.style.width=w+6;

    obj.style.height=h+17;

    x=setTimeout('expand()', 25);
  }
  else
  {
    obj.style.width=60;
    obj.style.height=174;
    clearTimeout(x);
  }
}

var drag=0;
var move=0;
function Dblclick()
{
  if (event.button==0)
    {
      obj.style.visibility="visible";
      obj.style.left=window.event.x;
      obj.style.top =window.event.y;
      obj.style.width=0;
      obj.style.height=0;

      obj.filters.item(0).apply();
      obj.filters.item(0).transition = 25;
      obj.filters(0).play(0.5);

      expand();
    }
}

function MouseMove()
{
  if(move==1)
    {
      obj.style.cursor="move";
      obj.style.left=window.event.x-l;
      obj.style.top=window.event.y-t;
    }
}

function MouseDown()
{
  if(drag) 
    {
      l = window.event.x - parseInt(obj.style.left);
      t = window.event.y - parseInt(obj.style.top);
      obj.style.zIndex+=1;
      move=1;
    }
  else
    {
      document.body.style.cursor='default';
      obj.style.visibility='hidden';
    }
}

function MouseStop()
{
  window.event.returnValue=false;
}

function MouseUp()
{
  move=0;
  obj.style.cursor="hand";
}

document.ondblclick=Dblclick;
document.onmousedown=MouseDown;
document.onmousemove=MouseMove;
document.ondragstart=MouseStop;
document.onmouseup=MouseUp;

相关文章推荐

弹出式菜单--自定义

  • 2011年04月17日 23:33
  • 880KB
  • 下载

js实现自定义鼠标右键-------Day45

每天最美好的事情,就是看到自己又进步了一点点.....

labview 的右键弹出式菜单例子

  • 2009年04月20日 20:56
  • 67KB
  • 下载

高逼格动画---自定义弹出式窗口+优化

今天给大家带来的给最底层的布局添加控件的原理分析。首先看下效果吧↓ 看完之后估计有些人认为很简单。具体你的看法是怎么样的我就不过多的猜测了,开始分析一下这个效果吧!首先大家看到了上面会有一块会弹上...

自定义PopupWindow实现底部弹出式菜单

现在很多应用都采用底部弹出式菜单,觉得挺好看的,先上图 底部弹出菜单通过自定义PopupWindow实现,很简单的一个自定义 1.自定义PopupWindow代码:public class M...

自定义控件之仿HD qq的弹出式小菜单

今天要给大家带来一个自定义控件,这个控件在平板qq HD中有放上效果图 我就截图了我的设备上的一张图,是弹出的状态.如果收起来的时候,覆盖的半透明的白色就会消失,并且弹出来的小菜单都会收回.这就是...

稳扎稳打Silverlight(29) - 2.0Tip/Trick之Cookie, 自定义字体, 为程序传递参数, 自定义鼠标右键, 程序常用配置参数

[索引页] [源码下载] 稳扎稳打Silverlight(29) - 2.0Tip/Trick之Cookie, 自定义字体, 为程序传递参数, 自定义鼠标右键, 程序常用配置参数 ...

IE屏蔽鼠标右键、禁止复制粘贴等功能

body oncontextmenu="return false" onselectstart="return false" ondragstart="return false" onbefo...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:自定义 IE 鼠标右键弹出式
举报原因:
原因补充:

(最多只允许输入30个字)