页面导航: 首页网络编程JavaScript应用技巧 → 正文内容

用JavaScript和注册表脚本实现右键收藏Web页选中文本

发布:dxy 字体:[增加 减小] 类型:转载
前两天在网上发现一个很好的站点,是用来做资料收藏的(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" 
 
       大家如果有兴趣可以自己试试!
浏览次数:载入中... 打印本文关闭本文文章来源

文章评论

共有 位脚本之家网友发表了评论我来说两句

同 类 文 章
最 近 更 新
热 点 排 行