admin管理员组

文章数量:1356778

I want to do the below with pure JavaScript if it is possible (or jQuery)

  1. the page is fully loaded.
  2. wait 5 seconds.
  3. alert('msg') once with no setInterval loops.

I want to do the below with pure JavaScript if it is possible (or jQuery)

  1. the page is fully loaded.
  2. wait 5 seconds.
  3. alert('msg') once with no setInterval loops.
Share Improve this question edited Apr 26, 2015 at 14:54 elixenide 44.9k16 gold badges78 silver badges102 bronze badges asked Apr 26, 2015 at 14:20 Egy SuccessEgy Success 1121 gold badge1 silver badge8 bronze badges 1
  • 2 The downvotes are a result of lack of research effort as this shouldn't be hard to research yourself and at least e up with a code attempt – charlietfl Commented Apr 26, 2015 at 14:52
Add a ment  | 

3 Answers 3

Reset to default 3

Try setTimeout:

document.onload = setTimeout(function () { alert('msg'); }, 5000);

jQuery solution:

$(document).ready(function()
{
    setTimeout(function()
    {
        alert('msg');
    }, 
    5000);
});
<script src="https://ajax.googleapis./ajax/libs/jquery/1.11.1/jquery.min.js"></script>

Use setTimeout, not setInterval. I kept the answer as verbose as the question.

Try this:

$(document).ready(function(){
    setTimeout(function(){ alert("msg");}, 5000)
})

do not forget put jquery reference to your html header:

<script src="http://code.jquery./jquery-2.1.3.min.js"></script>

本文标签: javascriptalert msg once5 seconds after the page loadedStack Overflow