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
enter
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 between the Code:
<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>