Home » Javascript31 March 2008

Website statistic (User Information) in Javascript

From the code below, you can get Resolution, Page title, Page url, Agent name, Browser name and Page Referrer.

<span id="more-51"></span>

<title>Website Statistic</title>

<script language="javascript" type="text/javascript">
// JavaScript for getting website statistic

// getting referrer
referer = ""+document.referrer;
var referer = referer.substring(0, 150);
var referer = escape(referer);

// getting page title
var title = ""+document.title;
var title = title.substring(0, 150);
var title = escape(title);

// getting url
var url = ""+document.location;
var url = url.substring(0, 150);
var url = escape(url);

// getting width and height of the page
// i.e. getting page resolution
var height = screen.height;
var width = screen.width;

// getting browser information
var agent = navigator.appName;
var agent_name = agent.substring(0,150);
var agent_name = escape(agent_name);

var version = navigator.appVersion;

var user = navigator.userAgent;
var user = user.substring(0,150);


<script language="javascript" type="text/javascript">
document.write("Resolution: "+width+"x"+height+"<br/>");
document.write("Title: "+title+"<br/>");
document.write("Url: "+url+"<br/>");
document.write("Agent Name: "+agent_name+"<br/>");
document.write("User: "+user+"<br/>");
document.write("Referer: "+referer+"<br/>");
Note: Referer is only displayed when you come to this page from some other page.

From Mukesh Chapagain's Blog, post Website statistic (User Information) in Javascript

php magento mukesh chapagain

Get New Post by Email

Find me on

Facebook Twitter Google+ LinkedIn RSS Feed