1:添加注册表:HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\<Menu Text> 设置默认值为html文件路径,添加值Contexts为)0xf3.
2:code : 在MSDN http://msdn.microsoft.com/en-us/library/aa753589(v=VS.85).aspx中有所讲解。MSDN原文:Set the default value of the key to the URL of the page that contains the script you want the context menu entry to execute. This script can obtain the parent window object, the screen where the context menu item was executed, from the menuArguments property of the external object.
大概就是说我们可以用window.external.menuArguments这个对象获取到内部的信息,如window,document这些常用的对象。所以我们就可以马上开工了,三下五去二不几分钟就搞定(代码很简单就直接Code了):
复制代码 代码如下:
<SCRIPT LANGUAGE = "JavaScript">
var oWindow = window.external.menuArguments;
var oDocument = oWindow.document;
var oSelect = oDocument.selection;
var oSelectRange = oSelect.createRange();
var sNewText = oSelectRange.text;//.substring(0,140);
var title=sNewText.length == 0?oDocument.title:sNewText;
if (title.length>0){
oWindow.open("http://service.weibo.com/share/share.php?title="+encodeURIComponent(title)+"&url="+encodeURIComponent(oDocument.URL)+"&source="+encodeURIComponent("破
狼")+"&appkey=1027675428&sourceUrl="+encodeURIComponent(oDocument.URL));
}
</SCRIPT>
看一个效果:
缺点:在这里只是简单获取的下文本值的内容,还没有找到获取选中html或者对象的方式,正在查找,如果有知道的请不吝赐教。我打算是可以解析出视频,图片等,发送。
下载【直接点击批处理运行,重启IE】
参考文献:
http://msdn.microsoft.com/en-us/library/aa753589(v=VS.85).aspx
http://blogs.msdn.com/b/oldnewthing/archive/2004/05/24/140283.aspx