...

View Full Version : detect connection speed and redirect



vpgunasekaran
11-17-2010, 07:59 PM
i have pasted below java script code. please check write or wrong

<script language = "JavaScript" type="text/javascript">
// Remove down to "ConnectionSpeed Detection section" if you don't want to use cookies
// If you drop a cookie it can be picked up on return by php or something else
function setCookie(name, value, expire) {
document.cookie = name + "=" + escape(value) + ((expire == null ?
"" : (";expires=" + expire.toGMTString())));
// alert('A cookie called '+name+' is now set with value: '+value); //enable to alert user of cookie
}
function getExpireDate() {
var expires = new Date();
expires.setTime((new Date().getTime() + 1000 * 60 * 60 * 24 * 365));
return expires;
}
// ConnectionSpeed Detection section
var datasize = 31468; // Size of data being transferred, in Bytes
var startTime = 0;
var endTime = 0;
var date = 0;
var ctype = "";
var textMessage = "";
function calcThroughput() {
var diffTimeMilliseconds = endTime - startTime;
var diffTimeSeconds = diffTimeMilliseconds / 1000;
var bits = (datasize * 8); // convert Bytes to bits,
var kbits = bits / 1024; // convert bits to kbits
var throughput1 = kbits / (diffTimeSeconds * 100 / 100);
throughput = throughput1 * .93; // account for IP packet header overhead - averages about 7%
setCookie("MediaThroughput", throughput, getExpireDate()); // Remove to not use cookie
if (throughput < 185) { ctype = "Home.aspx"; }
if (throughput > 185) { ctype = "intro.aspx"; }

textMessage = "Bandwidth: <B>" + ctype + "</B><br>time to load: (sec): <B>" + diffTimeSeconds + "</B><BR>kbits loaded:<B> " + kbits + "</B><BR>Throughput (kbps): <B>" + throughput + "</B>"
document.location = ctype;
}
</script>
<script language = "Javascript" type="text/javascript">
<!--
A bunch of binary data here in the actual file
-->
</script>
</head><body>
<script language = "Javascript" type="text/javascript">
date = new Date();
endTime = date.getTime();
calcThroughput();
</script>

automatic detect default page and check to low band version go to html page or high band version go to flash page.


please help!!!!!!!!!!!!!!!!!!!!!!!!!:)

Philip M
11-17-2010, 08:06 PM
When posting here please follow the posting guidelines and wrap your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.

What is the problem? It is no use just dumping a load of code and expecting people to wade throught it. Please explain why you think the code is not doing what you require.

There are no syntax errors, but when I alert (throughput) I get 0.
The whole thing seems flawed
endTime = date.getTime(); = number of milliseconds from 01/01/1970
var diffTimeMilliseconds = endTime - startTime; // startTime = 0;


It is your responsibility to die() if necessary….. - PHP Manual



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum