Javascript
Chapter Eighth using Windows
1. Display text on the status bar of the browser
<body onload=window.status= "Welcome to My Site" >
<a href=http://www.sohu.com>sohu</a>
</body>
2. Change the background color
<script>
Document.bgcolor= "Orange"
</script>
3. List background color
<body bgcolor =green>
<script>
document.write ("Current background color is:" +document.bgcolor)
</script>
</body>
4. Change text and link colors
<script>
Document.bgcolor= "Orange"
Document.fgcolor= "Blue."
Document.linkcolor= "Red"
</script>
<a href=http://www.sohu.com>sohu</a>
</body>
5. Change the title of the document
<script>
Name= "Mouse"
Document.title= "Welcome to" +name+ "' s house"
document.write (Document.title)
</script>
6. Show Modification Date
<script>
document.write ("Last modified on this page is" +document.lastmodified)
</script>
7. View the URL of the current document
<script>
document.write ("URL of this page:" +document.) URL)
</script>
8. View References page
<script>
document.write ("Reference page of this page is" +document.referrer)
</script>
9. Open a new browser window
<script>
window.open ("*.htm", "title", "Width=200,height=400,resizable=yes")
</script>
10. Close the remote window
Close.html:
<script>
document.write ("Body")
</script>
<form name=form1>
<input Type=button name=button1value= "Off" onclick=window.close () >
</form>
Open.html
<script>
window.open ("close.html", "Romote", "Width=200,height=400,resizable=yes")
</script>
11. Print Window
<script>
document.write ("Body")
</script>
<form name=form1>
<input Type=button value= Print onclick=window.print () >
</form>
12. Move the window
<form name=form1>
Horizontal direction <input Type=text name=x value=20>
Vertical direction <input Type=text name=y value=50>
<input type=button value= "Move window to ..." Onclick=window.moveto (document.form1.x.value,document.form1.y.value) >
</form>
<form name=form1>
Horizontal direction <input Type=text name=x value=20>
Vertical direction <input Type=text name=y value=50>
<input type=button value= "Move Window" Onclick=window.moveby (document.form1.x.value,document.form1.y.value) >
</form>
13. Change the window size
<form name=form1>
Horizontal direction <input Type=text name=x value=200>
Vertical direction <input Type=text name=y value=500>
<input type=button value= "Change window size to ..." Onclick=window.resizeto (Document.form1.x.value,document.form1.y.value) >
</form>
<form name=form1>
Horizontal direction <input Type=text name=x value=200>
Vertical direction <input Type=text name=y value=500>
<input type=button value= "Change window Size" Onclick=window.resizeby (document.form1.x.value,document.form1.y.value) >
</form>
14. Notify the user with a warning dialog box
<script>
Window.alert ("Welcome")
</script>
15. Use the prompt dialog box to accept input
<script>
Name=window.prompt ("Enter name", "name")
document.write ("Welcome:" +name+ "come Here")
</script>
16. Use the confirmation dialog box to make a decision for the user
<script>
Like=window.confirm ("Do you think it's OK?")
if (like==true)
document.write ("Thank you for your compliment")
Else
document.write ("Hope to get your compliments")
</script>
Chapter Nineth Using Strings
1. Using String objects
<script>
Mystring= "Gdgdfgfddddaaaaaaaaaaaabbbbbbbbbbbbbbbbbvbhg.<br>"
document.write (mystring)
document.write (Mystring.bold ())
document.write (Mystring.touppercase ())
</script>
2. Using substrings
<script>
str1= "FDSF 1111 gfdgfd dfdsf CCCC"
document.write (STR1)
document.write (str1.substring (0,13) + "<br>")
document.write (Str1.substr (20,11) + "<br>")
</script>
3. Connection string
<script>
Str1= "May and find"
Str2= "Peace,happiness and Prosperity.<br>"
document.write (str1+ "<br>")
document.write (STR2)
document.write (Str1.concat (STR2))
document.write (STR1+=STR2)
</script>
4. Format string variables
<script>
Str1= "Peace,happiness and Prosperity.<br>"
document.write (STR1)
document.write (Str1.big ())
document.write (Str1.small ())
document.write (Str1.bold ())
document.write (Str1.italics ())
document.write (Str1.strike ())
document.write (Str1.fontsize (6))
document.write (Str1.fontcolor (green))
</script>
5. Create Anchors and links
<script>
Str1= "This is the bigginning of the page.<br>"
Str2= "....<br>"
Str3= "This is the" page .<br>
str4= "link to the Start<br>"
str5= "link to the End<br>"
document.write (Str1.anchor ("Start"))
for (i=0;i<10;i++)
document.write (STR2);
document.write (Str3.anchor ("End"))
document.write (Str4.link ("#start"))
document.write (Str5.link ("#end"))
</script>
6. Determine string length
<script>
Str1= "This is the bigginning of the page."
document.write (str1+ "<br>")
document.write ("The length of the string is:" +str1.length)
document.write ("string all uppercase is;" +str1.touppercase ())
document.write ("string all lowercase is;" +str1.tolowercase ())
</script>
7. Search within a string
<script>
Str1= "This are the end of the line.<br>"
document.write (STR1)
document.write ("character end" in the position of the string is "+str1.search" ("End"))
document.write ("character dog at the position of the string is" +str1.search ("Dog"))
</script>
8. Locating characters in a string
<script>
Str1= "Spring is a" for flowers and trees and baby bunnles<br> "
document.write (STR1)
document.write ("The index for the second word ' and ' are" +str1.indexof ("and", 30))
Documednt.write ("The last index of the word ' and" +str1.lastindexof ("and"))
</script>
9. Replace text in a string
<script>
Str1= "Spring is a" for flowers and trees and baby bunnles<br> "
document.write (STR1)
Document. Write (Str1.replace ("and", ","))
</script>
10. String separation
<script>
Str1= "Spring is a" for flowers and trees and baby bunnles<br> "
document.write (STR1)
Str1array=str1.split ("")
document.write (str1array[0]+ "<br>")
document.write (str1array[1]+ "<br>")
document.write (str1array[2]+ "<br>")
document.write (str1array[3]+ "<br>")
</script>
Chapter tenth use date and time
1. Use Date Object
<script>
Cdate=new Date ("August 2,1989 12:30:00")
document.write (CDate)
</script>
2. Show local time and date
<script>
Cdate=new Date ()
document.write ("Current time is:" +cdate.togmtstring () + "<br>")
document.write ("Date and Time is:" +cdate.tolocalestring ())
</script>
3. Get time and date values
<script>
Cdate=new Date ()
document.write ("Show Current Week" +cdate.getday () + "<br>")
document.write ("Show Current Month" +cdate.getmonth () + "<br>")
document.write ("Show Current Date" +cdate.getday () + "<br>")
document.write ("Show Current Year" +cdate.getyear () + "<br>")
document.write ("Show Current Hour" +cdate.gethours () + "<br>")
document.write ("Show Current Minutes" +cdate.getminutes () + "<br>")
document.write ("Show Current Seconds" +cdate.getseconds () + "<br>")
</script>
4. Set time and date values
<script language=javascript>
Cdate=new Date ("December 25,1984")
document.write ("Show Date" +cdate+ "<br>")
document.write ("Set month" +cdate.setmonth + "<br>")
document.write ("Set Date" +cdate.setdate + "<br>")
document.write ("Set Year" +cdate.setyear + "<br>")
document.write ("Set hour" +cdate.sethours + "<br>");
document.write ("Set Minutes" +cdate.setminutes () + "<br>");
document.write ("Set seconds" +cdate.setseconds + "<br>");
document.write ("Show date and time after setting" +cdate);
</script>