小程序大作用—让你的主页更COOL
使用方法很简单,拷贝+粘贴即可。如果你稍懂一些HTML语言和JaveScript插件语法则更好。
#1 1.欢迎对话框
一进入网友的“家”,冷不丁蹦出来一个问好的对话框,是不是感到很亲切?没错,实现这效果的程序就是下面的几行:
<SCRIPT LANGUAGE="JAVASCRIPT">
alert ("\n "既来之,则安之"\n\n 欢迎您光临我的主页\n\n 别犹豫 \n\n LET'S GO!");
</SCRIPT>
(注:\n的作用是在对话框中换行)
#1 2.停留时间
网友进入你的“家”,抬头一看,有一个计时钟在不停地跳动,显示他的来访时间,很有趣吧!程序如下:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type"
CONTENT="text/html;CHARSET=gb2312">
<TITLE>停留时间</TITLE>
</HEAD>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
var ap_name = navigator.appName;
var ap_vinfo = navigator.appVersion;
var ap_ver =
parseFloat(ap_vinfo.substring(0,ap_vinfo.indexOf(′(′)));
var time_start = new Date();
var clock_start = time_start.getTime();
var dl_ok=false;
function init ()
{
if(ap_name=="Netscape" && ap_ver>=3.0)
dl_ok=true;
return true;
7}
function get_time_spent ()
{
var time_now = new Date();
return((time_now.getTime() - clock_start)/1000);
}
function show_secs () // show the time user spent on the side
{
var i_total_secs = Math.round(get_time_spent());
var i_secs_spent = i_total_secs % 60;
var i_mins_spent = Math.round((i_total_secs-30)/60);
var s_secs_spent = "" + ((i_secs_spent>9) ? i_secs_spent : "0" + i_secs_spent);
var s_mins_spent = "" + ((i_mins_spent>9) ? i_mins_spent : "0" + i_mins_spent);
document.fm0.time_spent.value = s_mins_spent + ":" + s_secs_spent;
window.setTimeout(′show_secs()′,1000);
}
// -->
</SCRIPT>
<BODY onLoad="init();
window.setTimeout(′show_secs()′,1);">
<form name="fm0" onSubmit="0">
<font size="-1"><I><FONT
COLOR="#888888">停留时间:</FONT></I></font><br>
<INPUT type="text" name="time_spent" size=7
onFocus="this.blur()">
</form>
</BODY>
</HTML>
#1 3.跑马灯
这是最常用的一种。在浏览器下面的状态条上,常看到主人不断地问候。程序如下:
<SCRIPT LANGUAGE="JavaScript">
<!--
function scroll(seed)
{
var
msg="欢迎您光临我的HomePage!^_^特别建议您使用800×600的分辨率参观。如有任何问题请发E-mail告之,不胜感激!";
var out = " ";
var c = 1;
if (seed > 100) {
seed--;
var cmd="scroll(" + seed + ")";
timerTwo=window.setTimeout(cmd,100);
}
else if (seed <= 100 && seed > 0) {
for (c=0 ; c < seed ; c++) {
out+=" ";
}
out+=msg;
seed--;
var cmd="scroll(" + seed + ")";
window.status=out;
timerTwo=window.setTimeout(cmd,100);
} else if (seed <= 0) {
if (-seed < msg.length) {
out+=msg.substring(-seed,msg.length);
seed--;
var cmd="scroll(" + seed + ")";
window.status=out;
timerTwo=window.setTimeout(cmd,100);
}
else {
window.status=" ";
timerTwo=window.setTimeout("scroll(100)",7);
}
}
}
timerONE=window.setTimeout(′scroll(100)′,50);
//-->
</SCRIPT>
这段程序请加在<body>语句的后面,var msg=" "语句中的问候内容可自由发挥。
好了,快将这些小程序粘贴到你的HomePage里面试一试,看看效果如何。同时也欢迎访问我的“家”:http://yc-dev.hb.cninfo.net/~pcworld