Advanced
1. display different greetings in different time periods
<Script Language = "JavaScript">
<! --
Var text = ""; day = new Date (); time = day. getHours ();
If (time> = 0) & (time <7 ))
Text = "night owl, pay attention to your health! "
If (time> = 7) & (time <12 ))
Text = "Today's sunshine is brilliant. What about your friend? "
If (time> = 12) & (time <14 ))
Text = "lunch break time. You need to stay asleep! "
If (time> = 14) & (time <18 ))
Text = "Have a good afternoon! "
If (time> = 18) & (time <= 22 ))
Text = "You're coming again. Don't talk to MM too long! "
If (time> = 22) & (time <24 ))
Text = "you should have taken a rest! "
Document. write (text)
// --->
</Script>
2. reflection effect in Water
<Script language = "JavaScript">
Function f1 ()
{
SetInterval ("mdiv.filters.wav e. phase +=10", 100 );
}
If (document. all)
{
Document. write ('Style = "filter: wave (strength = 3, freq = 3, phase = 0, lightstrength = 30) blur () flipv ()"> ')
Window. onload = f1
}
</Script>
3. a window that gradually grows
<Script Language = "JavaScript">
<! --
Var Windowsheight = 100
Var windowsswidth = 100
Var numx = 5
Function openwindow (thelocation ){
Temploc = thelocation
If
(! (Window. resizeTo & document. all )&&! (Window. resizeTo & document. getElementById ))
{
Window. open (thelocation)
Return
}
Windowsize = window. open ("", "", "scrollbars ")
Windowsize. moveTo (0, 0)
Windowsize. resizeTo (100,100)
Tenumxt ()
}
Function tenumxt (){
If (Windowsheight> = screen. availHeight-3)
Numx = 0
Windowsize. resizeBy (5, numx)
Windowsheight + = 5
Windowswidth + = 5
If (Windowswidth> = screen. width-5)
{
Windowsize. location = temploc
Windowsheight = 100
Windowswidth = 100
Numx = 5
Return
}
SetTimeout ("tenumxt ()", 50)
}
// -->
</Script>
<P> <a href = "javascript: openwindow ('HTTP: // www.ccjol.com ')"> enter </a>
4. Change the IE icon in the IE Address Bar
We need to first create a 16*16 icon (icon file) and save it as index. ico. Upload the icon file to the root directory and add the following code between the
<Link REL = "Shortcut Icon" href = "index. ico">
5. Move the webpage back at will
<A href = "javascript: history. go (-X)"> X </a> // replace X with the number of pages you want to return
// Change "-" to "+" to forward
6. A dialog box pops up when the cursor points
Add the following code between <body> </body>:
<A href onmouseover = "alert ('pop-up message! ') "> Displayed link text </a>
7. Right-click to bring up the Add favorites dialog box.
Add the following code between <body> </body>:
<Script Language = JavaScript>
If (document. all)
Document. body. onmousedown = new Function ("if (event. button = 2 | event. button = 3)
Window. external. addFavorite ('your website', 'Your website )")
</Script>
8. Random conversion of background images (a special effect that refreshes the mood)
Add the following code between
<Script Language = "JavaScript">
Image = new Array (4); // defines the image as an Array of the number of images.
Image [0] = 'tu0.gif '// path of the background image
Image [1] = 'tu1.gif'
Image [2] = 'tu2.gif'
Image [3] = 'tu3.gif'
Image [4] = 'tu4.gif'
Number = Math. floor (Math. random () * image. length );
Document. write ("<body background =" + image [number] + "> ");
</Script>
9. Click the link to show the color
Add the following code between <body> </body>:
<P onMouseMove = "anniu ()"> If you dare to touch me, I will show you some color! </P>
<Script Language = "VBScript">
Sub anniu
Document. fgColor = int (256*256*256 * rnd)
End sub
</Script>
10. Windows with Phantom effects falling from the sky
<Head>
<Script language = "JavaScript">
Function move (x ){
If (self. moveBy ){
Self. moveBy (0,-800 );
For (I = x; I> 0; I --)
{
Self. moveBy (0, 3 );
}
For (j = 200; j> 0; j --) {// if you think the window jitter is severe, replace 200 with a single digit.
Self. moveBy (0, j );
Self. moveBy (j, 0 );
Self. moveBy (0,-j );
Self. moveBy (-j, 0 );
}
}
}
</Scrip>
<Body bgColor = # ffffff onload = move (280)>
</Body>
</Head>
11. translucent display of the table
Add the following code between
<Style>
. Alpha {filter: Alpha (Opacity = 50)} // 50 indicates 50% transparency
</Style>
Add the following code between <body> </body>:
<Table border = "1" width = "100" height = "62" class = "alpha" bgcolor = "# F2A664">
<Tr>
<Td width = "100%" height = "62">
<Div align = "center"> cool! </Div>
</Td>
</Tr>
</Table>
Intermediate
1. Holiday countdown
<Script Language = "JavaScript">
Var timedate = new Date ("October 1,2002 ");
Var times = "National Day ";
Var now = new Date ();
Var date = timedate. getTime ()-now. getTime ();
Var time = Math. floor (date/(1000*60*60*24 ));
If (time> = 0)
Document. write ("now" + times + "and:" + time + "day") </Script>
2. click the button to print the current page
<Script Language = "JavaScript">
<! -- Begin
If (window. print ){
Document. write ('<form>'
+ '<Input type = button name = print value = "print this page "'
+ 'Onclick = "javascript: window. print ()"> </form> ');
}
// End -->
</Script>
3. click 'save as 'on the current page.
<Input type = "button" name = "Button" value = "Save this page"
OnClick = "document. all. button. ExecWB (4,1)">
<Object id = "button"
Width = 0
Height = 0
Classid = "CLSID: 8856F961-340A-11D0-A96B-00C04FD705A2">
<Embed width = "0" height = "0"> </embed>
</Object>
4. display the current system date
<Script language = JavaScript>
Today = new Date ();
Function date (){
This. length = date. arguments. length
For (var I = 0; I <this. length; I ++)
This [I + 1] = date. arguments [I]}
Var d = new date ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday ");
Document. write (
"<Font color =## 000000 style = 'font-size: 9pt; font-family: '> ",
Today. getYear (), "year", today. getMonth () + 1, "month", today. getDate (), "day ",
D [today. getDay () + 1], "</font> ");
</Script>
Elementary
1. Keep text scrolling
<MARQUEE> scroll text </MARQUEE>
2. Record and display the last modification time of the webpage
<Script language = JavaScript>
Document. write ("Last Update time:" + document. lastModified + "")
</Script>
3. Close the current window
<A href = "/" onClick = "javascript: window. close (); return false;"> close the window </a>
Close the current page in 4.2 seconds
<Script language = "JavaScript">
<! --
SetTimeout ('window. close (); ', 2000 );
-->
</Script>
Load the specified webpage in 5.2 seconds
<Head>
<Meta http-equiv = "refresh" content = "2; URL = http: // your URL">
</Head>
6. Add to favorites
<Script Language = "JavaScript">
Function bookmarkit ()
{
Window. external. addFavorite ('HTTP: // your url ', 'Your website name ')
}
If (document. all) document. write ('<a href = "#" onClick = "bookmarkit ()"> Add to favorites </a> ')
</Script>
7. Leave the hyperlink ununderlined
<Style type = "text/css">
<! -
A: link {text-decoration: none}
A: hover {text-decoration: none}
A: visited {text-decoration: none}
->
</Style>
8. prohibit right-click actions
<Script Language = "JavaScript">
Function click () {if (event. button = 2 | event. button = 3)
{
Alert ('prohibit right-clicking ');
}
Document. onmousedown = click // -->
</Script>
9. Set this page as the homepage
<Body bgcolor = "# FFFFFF" text = "#000000">
<! -- URL: http: // your url -->
<A class = "chlnk" style = "cursor: hand" HREF
OnClick = "this. style. behavior = 'url (# default # homepage )';
This. setHomePage ('your website name); "> <font color =" 000000 "size =" 2 "face =" "> set as homepage </font> </a>
</Body>