编程技术、软件应用与系统模拟

(Programming, Applicaiton and Simulation)



本站目录

 

首页
ASP/Access/IIS
DELPHI/PASCAL
PASCAL高级编程
C语言编程实例
WORD
Excel
MATLAB
MINITAB讲座
Windows
DOS
SAS
生物系统模拟
土壤水分剖析器
其他



镜像站点

 

主站
北美镜象站
欧洲镜象站(1)
欧洲镜象站(2)

本站 Google

[搜索]  [站内导航]
座右铭:
只做有益人类的事
不做有害人类的事


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+"");

© 1998-, 董占山, 版权所有。
转载文章请注明出处(www.sunfinedata.com/articles)。