添加IE右鍵菜單

來源:互聯網
上載者:User
菜單

<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';
//如果是連結、文本區或輸入框,則顯示IE菜單
 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';
    }
//禁止IE菜單
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.cnblogs.com\\nmailto:terry_52#163.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>
自訂滑鼠右鍵彈出式菜單
<a href=http://www.xrss.cn>網路大本營</a>
<SCRIPT LANGUAGE="JavaScript">
<!--
var MenuBarColor ='#6600FF';
DrawMouseRightButtonUpMenu();
//-->
</SCRIPT>
</body>
</html>



相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。