• 2006-03-23

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

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
    http://wolfchina.blogbus.com/logs/12266868.html

         前两天在网上发现一个很好的站点,是用来做资料收藏的(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("文章收藏页面被拦截!请设定你安装的拦截弹出窗口软件,使当前页面不被拦截!");
         }
       } 
    }
    </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_USERSoftwareMicrosoftInternet ExplorerMenuExt]

    [HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMenuExtLocalhost Test]
    @="http://10.1.1.19:8080/test/rightClick.jsp"

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


    历史上的今天:


    收藏到:Del.icio.us




    评论

  • 上面的扩展非常实用,但我发现个问题,通过右键提交数据后为什么总要打开两个窗口(一个loading,一个目标窗口),原版的和你的都是这样,我觉得这不太好,能有办法只打开一个窗口进行收藏吗????