Development of Internet Explorer right-key function table (ContextMenu) _javascript tips

Source: Internet
Author: User
Consult the MSDN Library "adding Entries to the Standard context menu" Development ContextMenu

1. IE additional ContextMenu is established by registering the code hkey_current_user\software\microsoft\internet Explorer\menuext
2. So just add a key value in that position, for example: new "Make 0rz" in IE, the right button will appear with the same name function

3. If we want to use shortcut keys on this feature, as with Windows Form, just add the & symbol before the English name.

For example: We change the key value from "Make 0rz" to "&make 0rz", then when the ContextMenu appears press M is to perform the function

4. Under the key value, there is an important key value is contexts, the main function is to define the timing of the occurrence of ContextMenu

Contains: Default (preset load), Images (on picture), control (on any of the controls), tables (on a table), text selection (plain text is white-selected), Anchor (on link)

If ContextMenu to contain more than two occurrences, then the value is logic or calculated and then brought into the

For example, in this example, we can add a DWORD type with a contexts name and a value of 23. The ContextMenu "Make 0rz" feature appears when you press the right button on "preset load", "on Link", "on picture".

5. There is also (default) This key value, the key value filled in the content is the user to perform ContextMenu function to whom to deal with, may be. html,. exe,. dll .... Wait a minute.

For example, in this example, I want to call JavaScript to perform functions, so I'm going to fill in "File://c:\program files\make0rz.js"

6. This is, in general, even the part of completing the registration. We made the. reg file convenient for users to install, the following is the case Regmake0rz.reg file:

Copy Code code as follows:

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. The following are the contents of the Make0rz.js:

Copy Code code as follows:

<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 + ', height= ' + height + ', 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>

Since the value of contexts is set to 0x23, the "Make 0rz" feature appears as "Preset load", "on Link", and "on picture" when you press the right button.
Preset load: In the margin of the page, press the right mouse button to perform the ContextMenu "make 0rz", indicating that the current page links to shorten the URL.
"On the link": On the text link, press the right button to execute ContextMenu "make 0rz", indicating that the text link to shorten the URL.
Preset load: In the picture link or picture, press the right button to execute ContextMenu "make 0rz", indicating the location of the picture to shorten the URL.

In JavaScript, use External.menuArguments.event to determine the timing at which the user presses the right button and gets the element
Using External.menuArguments.event.srcElement.href to get links to this element
Use External.menuArguments.location.href to get links to current pages

Then use window.open to open the 0rz.tw target page, to show the result of shortening the URL.
If the code is executed 30–33, there is a preview (Preview), and no preview screen is performed on 35-38. (Can be adjusted in accordance with the needs of the free)

8. Actual results map:
(1) In the blank, press the right button to execute ContextMenu "make 0rz", indicating that the current page links to shorten the URL. (with No Preview function rendering)

HTTP://TW.MSN.COM/?OCID=IEHP => http://0rz.tw/KR9Hf

(2) on the text link (news), press the right button to execute ContextMenu "make 0rz", indicating that the text link to shorten the URL. (rendered as Preview feature)

http://news.msn.com.tw/=> http://0rz.tw/7d2H6

(3) In the picture link or picture, press the right button to execute ContextMenu "make 0rz", indicating the location of the picture to shorten the site.

Http://sin.stb01.s-msn.com/i/53/79D3A7E9A23E21C6A510F09720CD2.jpg => Http://0rz.tw/JlTDN

This feature example can be downloaded, compressed file contains: Regmake0rz.reg Registration machine code installation file, Make0rz.js function, Delmake0rz.reg registration machine code Reverse installation file

Installation: Perform Regmake0rz.reg and place make0rz.js in C:\Program Files directory

Anti-Installation: Execute Delmake0rz.reg, delete C:\Program files\make0rz.js files on your own
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.