“如何在IE右键菜单中添加菜单项?”统统行不通!?

brotherq 2005-01-29 12:48:00
我按以下方法做了,可都行不通,哪位高手告诉我:
一、如何在IE右键菜单中添加菜单项
如果使用过Netants的朋友可能都知道,NetAnts在IE中添加了右键菜单功能,只要在页面的一个链接
或者图片上点击右键后在菜单中选择 Down By Netants 就可以调用Netants下载该链接指向的文件。在本
文中作者将介绍如何通过VB来实现这样的功能。
要实现在IE右键菜单中添加菜单项的功能,要依次实现以下步骤:
1、在注册表HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt项下建立一个
新项,项的名称既出现在菜单中的标题,例如你想建立的菜单项标题为Add URL,则新建项的名称为
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Add URL
2、将新建项的默认值设定为一个URL地址,当用户点击菜单项后,IE就会调用URL指向的页面中的脚
本,在目标页面的脚本中通过访问IE提供的external对象的menuArguments属性就可以访问IE中的页面中的
各种对象,例如链接、图片、表单域、被选中的文本等。详细的帮助请参考MSDN中关于InternetExplore object
的帮助,熟悉了Window对象才可以比较好的了解下面的脚本。
对于如何实现自身的程序访问menuArguments的问题,我们可以仿效Netants的做法,首先建立一个
OLE Automation对象,然后在脚本中调用该对象,并将页面信息传递对象处理。下面我们需要首先通过VB建立
一个对象:
打开VB,点击菜单: File | New ,在新建工程窗口中选择 ActiveX Dll 后按确定键建立一个ActiveX DLL
工程。然后在工程列表窗口中将Class1的Name属性更改为NetAPI,然后在NetAPI的代码窗口中添加如下代码:
Public Sub AddURL(URL As String, Info As String)
MsgBox Info, vbOKOnly, URL
End Sub
保存文件,将工程文件保存成NetSamp.vbp。然后在菜单中选择 File | Make NetSamp.dll建立对象动态
连接库。
接下来是注册库,在Windows目录下找到Regsvr32.exe,然后将其拷贝到netsamp.dll所在目录下,将
netsamp.dll的的图标拖到Regsvr32.exe上放开,这时Regsvr32.exe就会弹出对话框提示对象注册成功。
打开UltraEdit(或者其它文本编辑器)将下面的脚本代码输入编辑器中:

<script language="VBScript">

Sub OnContextMenu()
On Error Resume Next
set srcEvent = external.menuArguments.event
set EventElement = external.menuArguments.document.elementFromPoint(srcEvent.clientX, srcEvent.clientY)
set objNetSamp=CreateObject("NetSamp.NetAPI")

if srcEvent.type = "MenuExtAnchor" then
set srcAnchor = EventElement
do until TypeName(srcAnchor)="HTMLAnchorElement"
set srcAnchor=srcAnchor.parentElement
Loop
Call objNetSamp.AddUrl(srcAnchor.href,srcAnchor.innerText)
elseif srcEvent.type="MenuExtImage" then
if TypeName(EventElement)="HTMLAreaElement" then
Call objNetSamp.AddUrl(EventElement.href,EventElement.Alt)
else
set srcImage = EventElement
set srcAnchor = srcImage.parentElement
do until TypeName(srcAnchor)="HTMLAnchorElement"
set srcAnchor=srcAnchor.parentElement
if TypeName(srcAnchor)="Nothing" then
call objNetSamp.AddUrl(srcImage.href,srcImage.Alt)
exit sub
end if
Loop
Call objNetSamp.AddUrl(srcAnchor.href, srcImage.Alt)
end if
elseif srcEvent.type="MenuExtUnknown" then
set srcAnchor = EventElement
do until TypeName(srcAnchor)="HTMLAnchorElement"
set srcAnchor=srcAnchor.parentElement
if TypeName(srcAnchor)="Nothing" then
Call objNetSamp.AddUrl(EventElement.href,EventElement.innerText)
exit sub
end if
Loop
Call objNetSamp.AddUrl(srcAnchor.href,srcAnchor.innerText)
end if
end Sub

call OnContextMenu()

</script>

将文件保存到c:\program files 下,文件名为 geturl.htm
从上面的脚本可以看到,首先访问external.menuArguments属性,获得用户单击鼠标右键位置的对象,然
后根据对象的不同获得它的URL,然后建立IEContextMenu.IEMenu1对象并调用该对象的AddURL方法。
接下来是为右键菜单建立注册项,打开UltraEdit(或者其它文本编辑器)将下面的注册数据输入编辑器中
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\&Get URL]
@="c:\\program files\\geturl.htm"
"Contexts"=dword:00000022

将文件以reg为后缀保存,然后在Windows资源管理器中双击该文件将注册项添加到注册表中,然后打开
IE,右键点击一个连接或者图片,在弹出菜单中会出现一个Get URL项,点击该项,就会出现一个消息框显示
点击的连接或者图片的URL地址
...全文
149 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
brotherq 2005-01-29
  • 打赏
  • 举报
回复
回coutlin(斥侯):
这可是由微软网站提供的,给你两个地址:你去看看。
1、http://www.pstruh.cz/util/fav/favie5.asp?S=1
2、http://search.csdn.net/Expert/topic/59/59329.xml?temp=.9827692
klend 2005-01-29
  • 打赏
  • 举报
回复
可以用js屏蔽了右键,然后用层来模拟制作一个新的菜单
qixiao 2005-01-29
  • 打赏
  • 举报
回复
up
wzhiyuan 2005-01-29
  • 打赏
  • 举报
回复
up.
eyun 2005-01-29
  • 打赏
  • 举报
回复
up一下
scoutlin 2005-01-29
  • 打赏
  • 举报
回复
回Q哥
swlib.cachewrite

swlib是什么对象或类?
没给出?
huhanshan013 2005-01-29
  • 打赏
  • 举报
回复
楼主的做法绝对是属于病毒行为。
因为浏览了你的网站之后,永远的右键就修改了。
这样不可取,你可以考虑自己做一个右键啊。
又不是难事!
wen8u8 2005-01-29
  • 打赏
  • 举报
回复
这个到没有在意过,好像没有多大意义啊。楼主觉得呢?
ranqd 2005-01-29
  • 打赏
  • 举报
回复
还是不要搞这些的好
brotherq 2005-01-29
  • 打赏
  • 举报
回复
scoutlin(斥侯) 先生,我在http://community.csdn.net/Expert/topic/3695/3695790.xml?temp=.9737512拜读你的文章,关于“用ASP实现将收藏夹里的网址列表全部在线导入到数据库里面”。后来我在网上找到了一种办法,代码附下:可是发现也不行,是不是要把程序修改一下。
'ImportExportFavorites And ASP sample
Function BinaryToString(Binary)
Dim I, S
For I = 1 To LenB(Binary)
S = S & Chr(AscB(MidB(Binary, I, 1)))
Next
BinaryToString = S
End Function

Dim UID
UID = request.cookies("UID")
If len(UID)=0 Then
UID = request.querystring("UID")
If len(UID)=0 Then
randomize
response.redirect Request.ServerVariables("SCRIPT_NAME") & "?UID=" & rnd
end if
end If


If ucase(Request.ServerVariables("HTTP_User_Agent")) = "POSTFAVORITES" Then 'IE sends favorites as POSTFAVORITES UA
dim ByteArray
'Read the favorites
ByteArray = request.binaryread(request.servervariables("HTTP_Content_Length"))

'store the favorites to a cache
swlib.cachewrite "pstruh\favie\" & UID, BinaryToString(ByteArray)
end if

dim URL
const Message = "Click here to export And see your favorites/bookmarks"
URL = "http://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("SCRIPT_NAME") & "?UID=" & UID

'Write link with ImportExportFavorites And reload of the page.
Response.Write " <a href=""javascript:{external.ImportExportFavorites(0,'" & URL & "');window.location.reload();}"">"&Message&"</a>"
Dim Favorites
Favorites = swlib.getcache ("pstruh\favie\" & UID)
'Write stored favotites
If len(Favorites)>0 Then
Response.Write "<div style=background-color:silver>"
Response.Write "<h4>These are your favorites/bookmarks : </h4>"
Response.Write Favorites
Response.Write "</div>"
end if
scoutlin 2005-01-29
  • 打赏
  • 举报
回复
Set WshShell = Wscript.CreateObject(\"Wscript.Shell\")
WshShell.RegWrite \"HKCU\\Software\\Microsoft\\Internet Explorer\\MenuExt\\我的右键\", \"http://www.csdn.net/\"

昧着良心,唉
scoutlin 2005-01-29
  • 打赏
  • 举报
回复
在我眼里
就是病毒
这种网站去过一次不去第二次
myvicy 2005-01-29
  • 打赏
  • 举报
回复
你的意思没讲清楚吧。
iuhxq 2005-01-29
  • 打赏
  • 举报
回复
顶吧


不懂楼主为什么要这么做?
你能让所有的浏览者都导入注册表吗?有可能会被当成病毒

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧