Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: JavaScript, HTML
Expertise: Intermediate
May 24, 2004

Dynamic, Location-based Home Page Selection

When at home, I like to have my browser's home page to be different than at work. When I open up my browser on my laptop at home, it goes to news.google.com, when I open up the browser at work it goes to an internal engineering Web page. Save the following HTML on your local machine (or laptop) and point your browser to this file as the home page. When the browser is started, it runs the Javascript in this file and gets redirected automatically to the home page based on where you are i.e. home/work. This script looks at the IP address that the laptop (wireless) gets. At work I always get a 128.x.x.x type of address so the browser gets redirected based on that.

I had to upgrade the java plugin to Version 1.4.2_03 (build 1.4.2_03-b02) to make sure the getAddress() always got the latest DHCP address.


<html>
<head>
<META http-equiv="expires" content="0">
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
ip = java.net.InetAddress.getLocalHost().getAddress();

/* Upgrade from byte to int and maskoff the sign bit */
subnet = ip[0] & 0xff;

if (subnet == 128)
  location.replace("http://eng-internal");
else
  location.replace("http://news.google.com");

</script>

</body>
</html>
Siddharth Vajirkar
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap