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