吴伟贤のBlog

Feed Rss

js 注册表 实现右键收藏Web页选中文本

03.22.2011, js, by .

1:注册表注册

2:打开rightmenu.html处理

3:提交表单给test.php

 

 

 

注册表

Windows Registry Editor Version 5.00

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

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\右击菜单显示名]
@="http://127.0.0.1/dzx1.5/rightmenu.html"

 

rightmenu.html

提交到test.php

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<body>
    <form name=’formwiselife’ action=’test.php’ target=’_blank’>
        <input type=’hidden’ name=’title’ value=”><input type=’hidden’ name=’url’ value=”></form>
    <script language="JavaScript">
if (external.menuArguments)
{
  var selText = "";
  var strTitle = encodeURIComponent(external.menuArguments.document.title);
  var strURL = encodeURIComponent(external.menuArguments.document.URL);
  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");        
            document.getElementById("title").value=strTitle;
            document.getElementById("url").value=strURL;
            eval("document.formwiselife.submit();");          
         }
      }
}
    </script>
</body>
</html>

 

 

 

test.php内容

 

<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 leftMargin="0" topMargin="0" onload="setTimeout(‘Preloader();’,1000);">
<p title="网络收藏的文本框">网络收藏的文本框</p>
<textarea name="TextBox" id="TextBox" style="height:300px;width:100%;"></textarea>
</body>
</HTML>

评论已关闭。