Web programming

Units WEB1P and WEB2P

Practical JS1

  1. Write and run the Hello World script. Remember to save your files with the .htm/.html extension.
  2. 	<html>
       <head></head>
       <script type ="text/javascript">
       document.write("hello World")
       </script>
     </html>
  3. Insert an alert box into your code, with a welcome message in. Remember syntax -alert(“*****”)
  4. When you close a program quite often you get a dialogue box up to prompt the user to save their work or not. Below is the code to do this. Write and run the code. Add your own comments to the code.
  5. 	<HTML>
       <HEAD>
       <TITLE>My JavaScript page</TITLE>
       <SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
       <!-- Hide script from old browsers
       document.write(“This is my first web page”)
       if (confirm("Do you wish to save")) {
       alert("You said yes")
       }
       else {
       alert("You said no, all your work is now lost")
       }
     	// End hiding script from old browsers -->
       </SCRIPT> 
       </HEAD>
       <BODY BGCOLOR="WHITE">
       <NOSCRIPT>
       <H2>This page requires JavaScript.</H2>
       </NOSCRIPT>
       </BODY>
       </HTML>
  6. Write the code below, which detects which browser you are running. Try running the code in more than one browser to see if it works
	<HTML>
   <HEAD>
   <TITLE>What's your browser?</TITLE>
   </HEAD>
   <BODY BGCOLOR="WHITE">
   <H2>
   <SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
   <!-- Hide script from old browsers
	if (navigator.appName == "Netscape") {
   	document.write("You're running a Netscape browser")
   }
   else {
   	if (navigator.appName == "Microsoft Internet Explorer") {
		   document.write("You're running Internet Explorer")
	   }
   else {
   	document.write("You're not running Netscape or IE--maybe you should?")
	   }
   }
	// End hiding script from old browsers -->
   </SCRIPT>
   </H2>
   </BODY>
   </HTML>
 

Last updated by Prof Jim Briggs of the School of Computing at the University of Portsmouth

 
The web programming units include some material that was formerly part of the WPRMP, WECPP, WPSSM and WEMAM units.