參考 MSDN Library【Adding Entries to the Standard Context Menu】開發(fā) ContextMenu
1. IE 額外的 ContextMenu 是透過註冊機碼 HKEY_CURRENT_USER/Software/Microsoft/Internet Explorer/MenuExt 來建立
2. 所以只要在該位置下新增一個 Key 值,例如:新增【Make 0rz】則 IE 中按下右鍵就會出現(xiàn)相同名稱的功能
6. 這樣大致上,就算是完成註冊機碼的部份。我們透過製作 .reg 檔案方便讓使用者來進行安裝,以下是本範(fàn)例 RegMake0rz.reg 檔案:
復(fù)制代碼 代碼如下:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER/Software/Microsoft/Internet Explorer/MenuExt/&Make 0rz]
@="file://C://Program Files//Make0rz.js"
"Contexts"=dword:00000023
7. 以下是 Make0rz.js 的內(nèi)容:
復(fù)制代碼 代碼如下:
<script language="JavaScript" >
var obj = external.menuArguments.event.srcElement;
var str = obj.tagName;
if (str.toUpperCase() == 'A' || str.toUpperCase() == 'IMG') {
if (str.toUpperCase() == 'A') {
if (external.menuArguments.event.shiftKey) {
str = obj.firstChild.nodeValue;
}
else {
str = external.menuArguments.event.srcElement.href;
}
}
else {
str = external.menuArguments.event.srcElement.href;
}
}
else {
if (str.toUpperCase() != 'BODY') {
str = obj.innerText;
if (trim(str) == '') {
str = external.menuArguments.location.href;
}
}
else {
str = external.menuArguments.location.href;
}
}
//// Preview
//var url = 'http://0rz.tw/createget?redirect=1&url=' + encodeURIComponent(str);
//var width = 600;
//var height = 600;
// NO Preview
var url = 'http://0rz.tw/createget?redirect=0&url=' + encodeURIComponent(str);
var width = 160;
var height = 90;
var left = (screen.width - width) / 2;
var top = (screen.height - height) / 2;
var cmd = 'width=' + width + ',, top=' + top + ', left=' + left;
cmd += ', directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no';
newwin = window.open(url, 'windowname5', cmd);
if (window.focus) {
newwin.focus()
}
function trim(strValue) {
var regL = /^[?@/s]+/;
var regR = /[?@/s]+$/;
strValue = strValue.replace(regL, "");
strValue = strValue.replace(regR, "");
return strValue;
}
</script>
新聞熱點
疑難解答
圖片精選