前两天在网上发现一个很好的站点,是用来做资料收藏的(http://wolf.360doc.com)。
    这个网站提供了这么一个功能,可以直接将你选中的文字收藏起来,当时觉得很神奇的。后来研究了一下,发现用JavaScript和注册表脚本就可以实现这样的功能。
    右键收藏页面代码如下(我的收藏页面命名为rightClick.jsp):

代码如下:

<html>  
<script LANGUAGE="JavaScript">  
if (external.menuArguments)   
{  
  var selText = "";  
  var strTitle = escape(external.menuArguments.document.title);  
  var strURL = escape(external.menuArguments.location.href);  

  var doc = external.menuArguments.document;  

  if ((doc.selection.type == "None") || (doc.selection.type == "none"))  
  {  
     alert("请选中网页上欲保存的文字和图片后再收藏!");  
  }  
  else  
  {  
     selText = doc.selection.createRange().text;  
     if (selText == "")  
     {  
        alert("请选中网页上欲保存的文字和图片后再收藏!");  
     }  
     else  
     {  
        external.menuArguments.document.execCommand("Copy");  

        var objChild;                           // Window  
        var reWork = new RegExp('object','gi'); // Regular expression  
        objChild = window.open("SaveMenu.jsp?title="+strTitle+"&url="+strURL,"objChild","toolbar=no,menubar=no,resizable=yes,location=no,status=yes,z-look=yes,alwaysRaised=yes,scrollbars=no");  
        if(!reWork.test(String(objChild)))  
          alert("文章收藏页面被拦截!\r\n请设定你安装的拦截弹出窗口软件,使当前页面不被拦截!");  
     }  
   }    
}   
</script>  
</html> 

    文本显示页面代码如下(我的收藏页面命名为SaveMenu.jsp):   

代码如下:

<HTML>  
 <HEAD>  
  <title>网络收藏</title>  
<script language="JavaScript">  

<!-- hide me  
function Preloader()  
{  
  var Editor1 = document.getElementById('TextBox');  
  textRange = Editor1.createTextRange();  
  textRange.execCommand("Paste");  

}  

    
-->  
</script>  

</HEAD>  
 <body vLink="#261cdc" link="#261cdc" leftMargin="0" topMargin="5" onload="setTimeout('Preloader();',1000);">  
 <p title="网络收藏的文本框">网络收藏的文本框</p>  
 <textarea name="TextBox" id="TextBox" style="height:300px;width:100%;"></textarea>     
 </body>  
</HTML> 
  
注册表脚本如下:   

代码如下:

Windows Registry Editor Version 5.00  

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt]  

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Localhost Test]  
@="http://10.1.1.19:8080/test/rightClick.jsp" 
 

       大家如果有兴趣可以自己试试!