www.webdeveloper.com
Results 1 to 4 of 4

Thread: Page loading progress

Hybrid View

  1. #1
    Join Date
    May 2014
    Posts
    23

    Page loading progress

    Hi,
    I developed a game and I would like with js to have a progress loading in the title tag -> <head><tile>Loadning with %</title></head>. Practically when page loading before the game start in the title of doc must appear a progress % of loading. Somone told me is possible but I don' know how. Please help showing an example of that in js.
    Thanks
    Jakub

  2. #2
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    1,033
    Setting the <title> tag via javascript is fairly simple:
    Code:
    document.title = "This is a new title string";
    In your case the only 'trick' would be dynamically getting the progress (which I assume is stored in some variable) and inserting this into your dynamic <title> tag, either on a timed interval or whenever progress actually occurs (which depends on how your game is set up to load).

    So you'd end up with something like...
    Code:
    // Use a timed interval of 1 second to refresh the progress in the <title>
    var $progress = 0;
    var $progInterval = setInterval(function(){ document.title = "Loading " + $progress + "%"; if($progress >= 100) clearInterval($progInterval); }, 1000);
    
    
    // Or you can add a simpler bit of code to the end of whatever updates your progress
    document.title = "Loading " + $progress + "%";
    This is of course not exact for your situation since I haven't seen any of your code and thus do not know your variable names, available functions, events or methods. But the concept is simple enough and you shouldn't have too much trouble implementing this.

  3. #3
    Join Date
    May 2014
    Posts
    23
    Quote Originally Posted by Sup3rkirby View Post
    Setting the <title> tag via javascript is fairly simple:
    Code:
    document.title = "This is a new title string";
    In your case the only 'trick' would be dynamically getting the progress (which I assume is stored in some variable) and inserting this into your dynamic <title> tag, either on a timed interval or whenever progress actually occurs (which depends on how your game is set up to load).

    So you'd end up with something like...
    Code:
    // Use a timed interval of 1 second to refresh the progress in the <title>
    var $progress = 0;
    var $progInterval = setInterval(function(){ document.title = "Loading " + $progress + "%"; if($progress >= 100) clearInterval($progInterval); }, 1000);
    
    
    // Or you can add a simpler bit of code to the end of whatever updates your progress
    document.title = "Loading " + $progress + "%";
    This is of course not exact for your situation since I haven't seen any of your code and thus do not know your variable names, available functions, events or methods. But the concept is simple enough and you shouldn't have too much trouble implementing this.
    Thanks a lot this help me.

  4. #4
    Join Date
    May 2014
    Posts
    9
    You should wait after refresh the page.

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