JavaScript Snippets: Visitor Information
Knowing Information About Your Visitors Can Help You Customize Their Experience
Jun 21, 2010 Scripts & Tools, Web Design
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
Tags: JavaScript, Scripts, Web Design
JavaScript Snippets – Link Magic
Some of the Neat Little Tricks You Can Do With JavaScript Links
May 10, 2010 Internet Marketing, Scripts & Tools, Web Design
Open a new window with a link
Between Head Tags:
<Script>
function load() {
var load = window.open('http://www.domain.com','','scrollbars=no,
menubar=no,height=600,width=800,resizable=yes,toolbar=no,
location=no,status=no');
}
</Script>
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 http://www.domain.com 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('http://www.yoursite.com',
'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
——————————————————————————————
Tags: JavaScript, Scripts, Web Design
Recent Posts
- JavaScript Snippets: Visitor Information
- Copyright Registration – Making It Official
- Do Private Label Rights Let You Copy?
- When It’s OK to Copy
- Plagiarism, Fair Use and Your Website
- Copyrights DO Exist on the Internet
- JavaScript Snippets – Link Magic
- Thinkhost Review
- IX Webhosting Coupon Codes
- Ongoing Hostgator Coupon Codes