Results 1 to 2 of 2

Thread: Start and stop icon

  1. #1
    Join Date
    May 2013

    Start and stop icon

    Hi. I am not a javascript developer.. I have this page that call a servlet every x number of seconds.

    <script type="text/javascript">
    	var defaultDelay = 2000;
    	var maxDelay = 64000;
    	var reconnectDelay = defaultDelay;
        function reconnect (url) {
            var request = $.ajax({
                url: url,
                type: "GET",
                dataType: "text"
    		request.success(function(msg) {
    			document.getElementById("monitor").innerHTML = document.getElementById("monitor").innerHTML + msg;
    			document.getElementById("connection").innerHTML = "Connected";
    			reconnectDelay = defaultDelay;
    			setTimeout(function() { reconnect(url); }, reconnectDelay);
    		request.error(function(msg) {
    			document.getElementById("connection").innerHTML = "Unconnected";
    			if (reconnectDelay < maxDelay) {
    				reconnectDelay = reconnectDelay * 2;
    			setTimeout(function() { reconnect(url); }, reconnectDelay);
        function go() {
            var url = document.URL;
            url = url.substring(0, url.lastIndexOf('/'));
            url = url.substring(0, url.lastIndexOf('/'));
            url = url + '/monitor';
    <p id="connection">Connected</p>
    <ul id="monitor">
    I would like to create a icon to start and stop this function.
    So when the icon is pressed the page will call the servlet x number of senconds until the icon is pressed again... or a timeout has occurred. i.e. 5 min


  2. #2
    Join Date
    Jul 2008
    urbana, il
    <button onclick=go() >update</button>
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

Thread Information

Users Browsing this Thread

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

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