Develop Internet Explorer right-click menu (ContextMenu)

Source: Internet
Author: User

Refer to the MSDN Library [Adding Entries to the Standard Context Menu] to develop the ContextMenu

1. The additional ContextMenu of IE is created by using the volume machine code HKEY_CURRENT_USER \ Software \ Microsoft \ Internet Explorer \ MenuExt.
2. You only need to add a Key value at this position. For example, if [Make 0rz] is added, right-click IE and the same name will appear.

3. If you want to use the shortcut key for this function, just add the & symbol before the English name, just like developing a Windows Form.

For example, if we change the Key value from [Make 0rz] to [& Make 0rz], when the ContextMenu appears, pressing M is to execute this function.

4. Under this Key value, Contexts is an important Key value. The main function is to define the time when ContextMenu appears.

Including: Default (Default loading), Images (on the image), Control (on any Control item), Tables (on the table), and Text selection (when selecting plain Text reversed), Anchor (on the Link)

If the ContextMenu contains more than two types of appearance time, You can import the value into logic or computing.

For example, in this example, we can add a DWORD type named Contexts and a key value of 23. The "Make 0rz" function appears when you right-click the ContextMenu [preset loading], [LINK], and [Image.

5. There is also the (Default) key value. The key value is filled in with the content of the user who will handle the ContextMenu function, which may be .html#.exe,. dll .... And so on.

For example, in this example, if you want to call javascript to execute the function, enter [file: // C: \ Program Files \ Make0rz. js]

6. In this way, it is even the completion of the login terminal. We have implemented the. reg case to facilitate security for users. The following is the RegMake0rz. reg case in this example:

Copy codeThe Code is 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 content of Make0rz. js is as follows:

Copy codeThe Code is 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, 'cmdwname5', 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>

As a result, the value in Contexts is set to 0x23, so it indicates [preset loading], [on LINK], and [on Picture] Right-click, the [Make 0rz] function will appear.
[Preset loading]: in the blank area of the page, right-click and execute [Make 0rz] of ContextMenu, indicating that the current page Link is used to shorten the URL.
[On link]: On the text link, right-click the ContextMenu and execute [Make 0rz], which indicates that the text link is used to shorten the URL.
[Preset loading]: On the Image link or image, right-click and execute "Make 0rz" of ContextMenu, indicating that the image location is shortened.

In javascript, external. menuArguments. event is used to determine the user's right-click and obtain the element.
Use external. menuArguments. event. srcElement. href to obtain the link of this element.
Use external. menuArguments. location. href to obtain the link to the current page.

Then, we use window. open to open the target page 0rz.tw to display the results after the URL is shortened.
If the code is 30-33, a Preview is displayed. If the code is 35-38, no Preview is displayed. (Can be adjusted as needed)

8. Actual result textures:
(1) In the blank area, right-click the ContextMenu and execute [Make 0rz], which indicates that the current page Link is used to shorten the URL. (Displayed with the No Preview function)

Http://tw.msn.com /? Ocid = iehp => http://0rz.tw/KR9Hf

(2) On the text link (New News), right-click ContextMenu and execute [Make 0rz], which indicates that the text link is used to shorten the URL. (Presented as Preview)

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

(3) On the Image link or image, right-click and execute "Make 0rz" in ContextMenu to shorten the image position.

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

Click here to download this function example. The compressed files include: RegMake0rz. reg; register machine code Installation File; Make0rz. js function execution file; DelMake0rz. reg; register machine code uninstallation file.

Install: Run RegMake0rz. reg and place Make0rz. js in the C: \ Program Files directory.

Anti-installation: Run DelMake0rz. reg to delete the C: \ Program Files \ Make0rz. js file.

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.