www.webdeveloper.com
Results 1 to 7 of 7

Thread: [RESOLVED] Start running script

Hybrid View

  1. #1
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88

    resolved [RESOLVED] Start running script

    All,

    I am a complete newbie to JS and really don't know what I'm diving into. I am trying to use a JS based internet speed test and have it run automatically on page load. I put the window.onload command at the end of the script, but I can't get passed the first instruction listed with in the function. Nothing else happens after the text regarding "test in progress" is displayed. I appreciate any help you folks can provide.

    Code:
    <html>
    <head>
     	<script src="http://speedof.me/api/api.js" type="text/javascript">
        </script>
    </head>
    <body>
    <h2>Rental Xpress Internet Speed Test</h2>
    
    
    <button id="btnStart" type="button" onclick="btnStartClick()">Start Test</button>
    <div id="msg"></div>
    <script type="text/javascript">
    
    	SomApi.account = "SOM5326f3c941ee5";   //your API Key here
    	SomApi.domainName = "rxserver.no-ip.biz";      //your domain or sub-domain here 
    	SomApi.config.sustainTime = 4; 
    	SomApi.onTestCompleted = onTestCompleted;
    	SomApi.onError = onError;
    
    	var msgDiv = document.getElementById("msg");
    	
    	function btnStartClick() {
    		msgDiv.innerHTML = "<h3>Speed test in progress. Please wait...</h3>";
    		SomApi.startTest();
    		 
    	}
    	
    	function onTestCompleted(testResult) {
    		msgDiv.innerHTML = 
    		"<h3>"+
    			"Download: "   +testResult.download +"Mbps <br/>"+
    			"Upload: "     +testResult.upload   +"Mbps <br/>"+
    			"Latency: "    +testResult.latency  +"ms <br/>"+
    			"Jitter: "     +testResult.jitter   +"ms <br/>"+
    			"Test Server: "+testResult.testServer +"<br/>"+
    			"IP: "         +testResult.ip_address +"<br/>"+
    			"Hostname: "   +testResult.hostname +"<br/>"+
    		"</h3>";
    	}
    	
    	function onError(error) {
    		msgDiv.innerHTML = "Error "+ error.code + ": "+error.message;
    	}
    	
    window.onload=btnStartClick();
    
    
    </script>
    </body>
    </html>

  2. #2
    Join Date
    Mar 2014
    Posts
    40
    And if you write window.onload=btnStartClick; (whitout () )

  3. #3
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88
    I get the same results with or without the () following btnStartClick

  4. #4
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    1,031
    Since you say nothing seems to happen after you see the 'test in progress' message it would appear your issue is with the next line: SomApi.startTest();

    Can you press F12 and check the console tab to see if any errors come up in the log when the page loads?

  5. #5
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88
    Here is what is displayed in the CONSOLE tab:

    > Date: Thu Mar 20 2014 core.js?v=2.62:8
    > Ver: 2.7 core.js?v=2.62:8
    > URL: http://speedof.me/api/core.html core.js?v=2.62:8
    > User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36 core.js?v=2.62:8

  6. #6
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    1,031
    It looks like this is an issue with the speed test api/script if anything. From what I can tell the 'SomApi.startTest()' line is being called too soon, even though it's not triggering an error. The stuff you see appear in your console shows up after the speed test api has fully initialized. This seems to take a short amount of time, even after the window has loaded (the window onload event triggers once all of the resources for a page have been loaded, but scripts can still be busy executing stuff).

    I found that setting a slight delay on the speed test function was the only way to solve it:
    Code:
    (function(){ setTimeout(btnStartClick, 1500); })();
    But again I think this should be looked at from the speed test api standpoint first. There may very well be an event trigger that fires once the speed test object has fully been initialized. You'll have to check their documentation but if it exist then you would be better off using that to fire the btnStartClick() function instead of using the windows load event.

  7. #7
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88
    Thank you, Sup3rkirby. Your solution worked like a charm!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles