DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript綜合知識 >> 簡單幾行JS Code實現IE郵件轉發新浪微博
簡單幾行JS Code實現IE郵件轉發新浪微博
編輯:JavaScript綜合知識     

最近剛開通新浪圍脖,突發奇想,想做個浏覽器插件實現文字新聞等的轉發圍脖的插件。本以為應該用C++寫個插件的(c#那麼大個殼有時真的讓人頭疼),但 是google了一下,手氣真的不錯,搜到了,幾篇關於IE插件的開發。用的Javascript,和添加注冊表就可以完全搞定。插件用 javascript寫那就不用多說,浏覽器本身就支持的,不用額外安裝。添加注冊表手動可以添加,但是麻煩所以寫了一個批處理搞定。

1:添加注冊表:HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMenuExt<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

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved