﻿# 如何在 IE 新增自訂的「右鍵選單」

如果要在 IE 新增自訂的「右鍵選單」有兩個步驟要做：

1.  新增一筆 Registry 紀錄，以下檔案存檔後 Double-Click 即可安裝完成。

> **Install\_MyContextMenu.reg**
> 
> * * *
> 
> REGEDIT4
> 
> \[HKEY\_CURRENT\_USER\\Software\\Microsoft\\Internet Explorer\\MenuExt\]
> 
> \[HKEY\_CURRENT\_USER\\Software\\Microsoft\\Internet Explorer\\MenuExt\\我的右鍵選單\]  
> @="http://www.yourdomain.com/accept\_IE\_MenuExt.htm"
> 
> * * *

2\. 寫一個 accept\_IE\_MenuExt.htm 網頁到你的網站 ( [https://web.archive.org/web/20260929202048/https://www.yourdomain.com/](https://web.archive.org/web/20260929202048/https://www.yourdomain.com/) ) 去

> 這個網頁其實只有 JavaScript 的部分而已。如下：
> 
> * * *
> 
> <html>  
> <head>  
>  <script LANGUAGE="JavaScript">
> 
>  if (external.menuArguments)  
>  {  
>      var win = external.menuArguments;  
>     
>   // 原本這頁的網址  
>      // win.location.href;  
>     
>   // 原本這頁的頁面標題(<title>)  
>      // win.document.title;
> 
>   // 這可以抓到你在頁面中按右鍵的時候是在哪一個 TAG 上面按的  
>   // 底下的範例是抓取「超連結」時按右鍵選單的  
>      if (win.event.srcElement.tagName == "A")  
>   {  
>          LinkUrl   = win.event.srcElement.getAttribute("HREF");  
>          LinkTitle = win.event.srcElement.innerText;  
>      }  
>     
>   // 另開新視窗做一些你想做的事  
>      void(window.open('http://www.yourdomain.com/somepage.aspx?url='+encodeURIComponent(LinkUrl)+'&title='+encodeURIComponent(LinkTitle)));  
>  }  
>  else  
>  {  
>   // 如果有人誤闖此頁，就讓他回到上一頁吧！  
>      history.go(-1);  
>  }  
>  </script>  
> </head>  
> </html>
> 
> * * *
> 
> 備註：
> 
> -   程式中的 external.menuArguments 就是開啟這個頁面的 window 物件，有了 window 物件，你幾乎可以做任何你想做的事了。
>     

參考資料：

-   How to add to the standard context menus of the WebBrowser control  
    [https://web.archive.org/web/20130618112829/http://support.microsoft.com/kb/177241/en-us](https://web.archive.org/web/20130618112829/http://support.microsoft.com/kb/177241/en-us)
