Programming and Application(编程与应用)


Content(目录)




Linux


MySQL
Office















 
PCNow 30-Day Free Trial, Remote PC Access
 
Logo_234x60

Using JavaScript to Improve Your Website


Using JavaScript to Improve Your Website

Zhanshan Dong


There are a plenty of places in your webpages to which you can use JavaScript to improve. The following lists some usually used examples. To be notice, the following scripts are from a various sources, some written by myself, some copied from other place, some modified by meself. But all of these scripts are free to use.

Untrap your page from other pages' frame:
Web pages in the internet were or are being procuded by a various of people, like professional web pape disigners, scientific researchers, teachers, workers, students, and even pupils. The quality of web pages is in a exrtemely wide range. When you surf in the internet, you can often see some nicely designed pages were trapped in a very less qualified page. Whenever it happens, you will feel sorry for the nicely designed page. But there is one simple way to overcome the problem, just put the following javascript command into your page. You page is always the top page wherever visitors come from.
<SCRIPT type="javascript">
if (self != top) top.location = self.location;
</script>

Control the font size by keyboard:
When visit a page with small font size, it is nice to press one key to increase the entire font size of the page. The following script can be used in this purpose.
  // increase or decrease the font size
  var i=0;
  document.onkeydown = zoom;
  function zoom()
  {
  	var IEKey = event.keyCode;
  	if (IEKey == 76) // L -> increase the font size
  	{
  		i++;
  		document.body.style.zoom=1+i/10;
  	}
  	if (IEKey == 83) // S -> descrease the font size
  	{
  		i--;
  		document.body.style.zoom=1+i/10;
  	}
  	if (IEKey == 82) // R -> Restore the original font size
  	{
  		document.body.style.zoom=1;
  		i=1;
  	}
  }

Detect the domain names of server and referer document. These information is important when you write a page can show different things in different servers.

alert(window.location + "\n" +document.referrer);

Detect the IP address of your users. The following javascript code can do that if your server provide SSI.

// This part gets the IP
var ip = '<!--#echo var="REMOTE_ADDR"-->';

// This part is for an alert box
alert("Your IP address is "+ip);

// This part is for the status bar
window.defaultStatus = "Your IP address is "+ip;

// This part is for the title bar
document.write("Your IP address is "+ip+"");
©董占山Zhanshan Dong

Post comments(留言)

Name(名字):

Comment(内容):


由Google提供

SunfineData Products|U's Bargain Network|Contact Me(与我联系)
© 1998-, 董占山, 版权所有, 欢迎转载文章链接。
转载文章和软件请注明出处(http://articles.sunfinedata.com/)。