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.

<SCRIPT LANGUAGE="JavaScript">
document.write("<B>"+navigator.appVersion+"</B><P>");
</SCRIPT>

Alternate Version

<SCRIPT LANGUAGE="JavaScript">
if (document.all)
     var version=/MSIE \d+.\d+/
if (!document.all)
     document.write("You are using "+navigator.appName+"
"+navigator.userAgent)
else
document.write("You are using "+navigator.appName+"
"+navigator.appVersion.match(version))
</script>

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 ");
document.write(document.referrer+"</B>");
}
</script>

Browser Language Detect & Redirect

<script>
/*Browser Language Redirect script (By JavaScript Kit)
For this and over 400+ free scripts, visit http://www.javascriptkit.com
his notice must stay intact*/

//Enter ISO 639-2 letter Language codes to detect 
//(see: http://www.w3.org/WAI/ER/IG/ert/iso639.htm):
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 : 
navigator.userLanguage
var gotodefault=1

function redirectpage(dest){
     if (window.location.replace)
          window.location.replace(dest)
     else
          window.location=dest
}

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

if (gotodefault)
     redirectpage(langredirects[langcodes.length-1])
</script>

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:

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

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

<script>
document.write("Your IP address is: "+ip+"");
</script>

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

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

Navigate

Hosting Info

Hosting Help

Online Business

Join Our Newsletter

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


Warning: Parameter 1 to W3_Plugin_TotalCache::ob_callback() expected to be a reference, value given in /home4/hylidix/public_html/mymultihost.com/wp-includes/functions.php on line 3644