Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    detect connection speed and redirect

    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!!!!!!!!!!!!!!!!!!!!!!!!!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,151
    Thanks
    203
    Thanked 2,548 Times in 2,526 Posts
    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
    Last edited by Philip M; 11-17-2010 at 07:19 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •