简体   繁体   English

如何实际定制IE上下文菜单?

[英]How to practically customize IE context menu?

I need to add one menu item in IE context menu. 我需要在IE上下文菜单中添加一个菜单项。 It is similar with Google customized context menu "Search Google for xxx" when you right click on IE. 当您右键单击IE时,它与Google自定义上下文菜单“搜索Google for xxx”类似。

I did a research and found that overriding IDocHostUIHandler::ShowContextMenu in a IE BHO can customized IE context menu. 我做了一项研究,发现在IE BHO中覆盖IDocHostUIHandler :: ShowContextMenu可以自定义IE上下文菜单。 The sample project can be found in Popup blocker project published in codeproject. 示例项目可以在codeproject中发布的Popup阻止程序项目中找到。 It works well and is easy to implement. 它运行良好,易于实现。 However this approach has a problem. 然而,这种方法存在问题。 The problem is it will conflict with other add-ons' context menu customization per MSDN. 问题是它会与每个MSDN的其他附加组件的上下文菜单自定义冲突。

In MSDN Internet Explorer Center forum, there are some discussions about this topic. 在MSDN Internet Explorer Center论坛中,有一些关于此主题的讨论。 However there is not a proper implementation posted. 但是没有发布适当的实施。

If anybody has experience on this, please share your idea. 如果有人有这方面的经验,请分享您的想法。 Thanks! 谢谢!

See Adding Entries to the Standard Context Menu on MSDN. 请参阅在MSDN上将条目添加到标准上下文菜单

For some sample code, download and extract the Web Accessories for Internet Explorer 5 (the mechanism still works in IE versions up to and including 8). 对于某些示例代码,请下载并解压缩Internet Explorer 5Web附件 (该机制仍适用于IE版本,包括8)。 Look at ie5wa.inf and *.html for examples of various IE context menu extensions. 查看ie5wa.inf*.html以获取各种IE上下文菜单扩展的示例。

Note that the abive is achieved without COM, purely via one registry setting and a file containing a blob of script (Javascript, JScript, VBScript etc.) The script (JScript, VBScript) may in turn work with COM objects, should your menu action logic reside in such an object, eg 请注意,abive是在没有COM的情况下实现的,纯粹是通过一个注册表设置和一个包含blob脚本(Javascript,JScript,VBScript等)的文件。如果你的菜单操作,脚本(JScript,VBScript)可以反过来使用COM对象逻辑驻留在这样的对象中,例如

  • create a HKCU\\Software\\Microsoft\\Internet Explorer\\MenuExt\\My &Context Menu" registry key ( &` precedes the menu accelerator letter, if any) 创建HKCU\\Software\\Microsoft\\Internet Explorer\\MenuExt\\My &Context Menu" registry key ( &'在菜单加速器字母前面,如果有的话)
  • set the default value for the key to point to a file containing the script code implementing the context menu action(s), possibly interacting with a COM object (must support IDispatch IIRC; also read up on the My Computer Security Zone ) 设置密钥的默认值以指向包含实现上下文菜单操作的脚本代码的文件,可能与COM对象交互(必须支持IDispatch IIRC;也可以在我的计算机安全区读取)
  • create a binary contexts value ( 0x02 for images, 0x10 for selections, etc.) which regulates when the new context menu should be displayed 创建一个二进制contexts值(图像为0x02 ,选择为0x10等),用于调整何时应显示新的上下文菜单

I customized my IE in order to navigate to a selected text. 我定制了IE以便导航到选定的文本。 You can read the full story and get detailed source code here . 您可以在此处阅读完整的故事并获取详细的源代码。

The hearth of my solution is built around the following javascript code and the Registry key [HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\MenuExt]: 我的解决方案的中心是围绕以下javascript代码和注册表项[HKEY_CURRENT_USER \\ Software \\ Microsoft \\ Internet Explorer \\ MenuExt]构建的:

  var parentwin = external.menuArguments;
  var doc = parentwin.document;
  var sel = doc.selection;
  var rng = sel.createRange();
  var str = new String(rng.text);

  if(0 < str.length)
  {
    if (str.indexOf("http")!=0)
        window.open("http://"+str, "_blank");
    else 
        window.open(str, "_blank");
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM