2

I develop a mobile app using phonegap. I have two file html (splash.html , index.html). So, I'd like that the app start with splash.html and after X seconds, change page to index.html.

How can I do this using javascript?

4 Answers4

5

With JavaScript:

setTimeout(function() {
  window.location.href = 'index.html';
}, 2000);

Without JavaScript:

<head>
  <!-- ... -->
  <meta http-equiv="refresh" content="2; url=index.html">
</head>
Amadan
  • 191,408
  • 23
  • 240
  • 301
  • @SamuelLiew: That is not a JavaScript issue, it is a PhoneGap issue: `` in the app's `config.xml `. – Amadan Jul 07 '15 at 07:26
  • What means by : content=2 ? – partho Jul 07 '15 at 08:58
  • @partho: Not `content=2`, see where the quotes are. `` "fakes" HTTP headers. One such header is `Refresh`. The content we want to give this header is `2; url=index.html`: in two seconds, reload the page from `index.html`. – Amadan Jul 07 '15 at 09:00
  • Oh, I didn't notice well. And now I got that. – partho Jul 07 '15 at 09:04
3

try this:

function delay(){
setTimeout(function(){
    window.location.href='index.html'
},5000);}
2

You can perform this task only using HTML redirection meta tag like following :

<meta http-equiv="refresh" content="5; url=http://yoursite.com/">

The fact that I didn't precised any file after your site absolute URL is because the default file are loaded, and index.html is a default file.

Anwar
  • 4,162
  • 4
  • 41
  • 62
0
function delay(){
setTimeout(function(){
    window.location.href='index.html'
},5000);}
Michael
  • 324
  • 2
  • 20