You know that some special effect in web pages can be achieved only by HTML code. Follow the last article, we will learn how to limit the time of viewing the web page. Sometimes we need to do this. For example, when you want to build a website for the exam online, you need to limit the time because the students should hand on the test paper on time. This special effect need the help of the HTML codes and a div tag. Now let us learn how to achieve it by HTML codes.

clip_image002

Step1:

Open the web page you have built.

Sep2:

Set focus on the position that you want to add a Div tag. Then select the [insert]-[layout objects]-[Div tag] command. There will be a “insert div tag” dialog box appearing. In the ID textbox, input “a”. like the following picture showing:

clip_image004

Step3:

Change to the code view. Put the following codes into the section between <head> and </head>.

  1. <script language=javascript>
  2.  
  3. Var yuan=9
  4.  
  5. Function timelimit()
  6. {
  7.  
  8. Var now=new Date()
  9. Var seconds=now.getSeconds()
  10.  
  11. If(seconds++)
  12. {yuan- -}
  13.  
  14. a.innerText=”you have “+yuan+” seconds to view
  15. setTimeout(timelimit()”,1000)
  16.  
  17. if(yuan=0)
  18. self.close()
  19. }
  20.  
  21. </script>

Maybe you have some confusion about them. Script means definite the content of program script. It is used in starting and ending to control the program. “var now” means start to time. a.innerText means the “you have “+yuan+” seconds to view” text will appear in the div tag. And self.close means the web page will close automatically on time. generally speaking, we use object. Action to express the action of objects. You can see it isn’t difficult.

Setp4:

Change to the spilt view. Add the code “onLoad=timelimit()” in to <body> sentence.

Setp5:

Save the document and preview it in the internet explorer. The effect is like this:

clip_image006

Now the special of limiting the time of viewing the web page is OK. In fact, this special effect is very easy. You just need to memorize the meanings of some codes such as timelimit, timeout, self close.

For help, advice, tips and tricks, challenges, feel free to visit ourDoNotYet forum or Submit your good resource to share.

Reminder: Unless stated otherwise, all resources published on this site are NOT for commercial use. To use any resource from this site for commercial purposes, please contact the author.

Related Posts