-
2006-03-23
用JavaScript和注册表脚本实现右键收藏Web页选中文本
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
前两天在网上发现一个很好的站点,是用来做资料收藏的(http://wolf.360doc.com)。
http://wolfchina.blogbus.com/logs/12266868.html
这个网站提供了这么一个功能,可以直接将你选中的文字收藏起来,当时觉得很神奇的。后来研究了一下,发现用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"大家如果有兴趣可以自己试试!随机文章:
心学大师 王守仁 2007-10-16“激情创业”综合症 2007-09-21秋水仙碱、别嘌醇、立加利仙、通益风宁片、丙磺舒 2007-08-13深入理解abstract class和interface 2007-07-04非常优秀的Javascript(AJAX) 开发工具:Aptana 2007-07-04
收藏到:Del.icio.us








评论