Bookmark and Share

JavaScript Snippets: Visitor Information

Knowing Information About Your Visitors Can Help You Customize Their Experience

Today I have some JavaScript code snippets that provide information about visitors to your website. This can be useful if you want to display information to a visitor about their browser configuration or customize their browsing experience.

Browser Version
Place this code on your page where you want the user’s browser version to be displayed.


Alternate Version

if (document.all)
     var version=/MSIE \d+.\d+/
if (!document.all)
     document.write("You are using "+navigator.appName+"
document.write("You are using "+navigator.appName+"

Advanced Browser User Info

Insert this code into your web page to display your user’s browser information.

<script type="text/javascript">
document.write("Browser CodeName: " + navigator.appCodeName);
document.write("<br /><br />");
document.write("Browser Name: " + navigator.appName);
document.write("<br /><br />");
document.write("Browser Version: " + navigator.appVersion);
document.write("<br /><br />");
document.write("Cookies Enabled: " + navigator.cookieEnabled);
document.write("<br /><br />");
document.write("Platform: " + navigator.platform);
document.write("<br /><br />");
document.write("User-agent header: " + navigator.userAgent);
document.write("<br /><br />");
document.write("<strong>Screen Resolution</strong><br />");
document.write("Color Depth: " + window.screen.colorDepth);
document.write("<br />");
document.write("Current Resolution: " + window.screen.width);
document.write(" x " + window.screen.height);
document.write("<br />");
document.write("Max Resolution: " + window.screen.availWidth);
document.write(" x " + window.screen.availHeight);
if (navigator.javaEnabled()) {
document.write('<p>Java is enabled.<\/p>');
} else {
document.write('<p>Java is not enabled.<\/p>');
if (document.referrer) {
document.write("<B>Thanks for visiting us from ");

Browser Language Detect & Redirect

/*Browser Language Redirect script (By JavaScript Kit)
For this and over 400+ free scripts, visit
his notice must stay intact*/

//Enter ISO 639-2 letter Language codes to detect 
var langcodes=new Array("en", "fr", "es", "ja", "zh", "default")

//Enter corresponding redirect URLs (last one is for default URL):
var langredirects=new Array("index.htm", "french.htm", "spanish.htm", 
"japan.htm", "chinese.htm", "index.htm")
var languageinfo=navigator.language? navigator.language : 
var gotodefault=1

function redirectpage(dest){
     if (window.location.replace)

for (i=0;i<langcodes.length-1;i++){
     if (languageinfo.substr(0,2)==langcodes[i]){

if (gotodefault)

User IP Address Display

This uses SSI to display a visitor’s IP address. Your server needs to have SSI enabled for this for work. Also, you may need to give your web page a “.shtml” extension instead of “.html” or “.htm”. Place the following between the <head></head> tags on your page:

var ip = '<!--#echo var="REMOTE_ADDR"-->'

Put this code in your HTML code where you want the user’s IP address to be displayed:

document.write("Your IP address is: "+ip+"");

Useful JavaScript Tools
Better than Pop-ups, Pop-ins, and Pop-Unders… Optimize your advertising real estate and increase ad conversions with Corner Stay Ads & Peel Away Ads

JavaScript Snippets – Link Magic

Some of the Neat Little Tricks You Can Do With JavaScript Links

Open a new window with a link

Between Head Tags:

function load() {
var load ='','','scrollbars=no,

Your Link:

<a href="javascript:load()">Open Window</a>

As you can see in the code example above, you can control a some attributes of the new window. You would replace with your own link. Then you can decide the hieght and width of the new window and whether or not the user can resize it (yes/no), if it shows the scrollbars or if the browser toolbar and menu bar should show.

Close a Window With A Link

<a href="javascript: self.close()">Close Window</a>

Reload a Window With A Link

<a href="javascript: window.location.reload()">Reload Window</a>

Go Back 1 Page With A Link

<a href="javascript: history.go(-1)">Back</a>

Print Page

<a href="#" onClick="window.print()">Print Page</a>

Add To Favorites (Internet Explorer Only)

<a href="javascript:window.external.AddFavorite('', 
'Your Site Name')">Add to Favorites</a>


Useful JavaScript Tools
Better than Pop-ups, Pop-ins, and Pop-Unders
Optimize your advertising real estate and increase
ad conversions with Corner Stay Ads & Peel Away Ads


Hosting Info

Hosting Help

Online Business

Join Our Newsletter

Copyright © 2002-, Hylidix LLC - #74, Reading, MA 01867-0174. All rights reserved. Disclaimer | Disclosure