0

Possible Duplicate:
Is there some way to introduce a delay in javascript?

On my website I use a modal popup for visitors to enter some info before they can enter the website. I use a script found here which I really appreciate because it seems to work on every browser (also the ones without position:fixed support).

So when you visit my website you click on this link and because of the

onclick="ShowModalPopup('dvPopup'); return false;" 

the window pops up - works perfectly.

However, I want the window to popup automatically say 3 seconds after the website is loaded. I would like to use this script for the popup so I'm looking for a way to execute the onclick after 3 seconds.

Community
  • 1
  • 1
user1172465
  • 63
  • 2
  • 7
  • http://stackoverflow.com/questions/24849/is-there-some-way-to-introduce-a-delay-in-javascript – Robert Harvey Jan 15 '13 at 18:37
  • http://api.jquery.com/delay/ – Robert Harvey Jan 15 '13 at 18:37
  • Just a note: if the window.open is not invoked by user action the popup blocker will engage the window, therefore the Mike Brant code is the correct one, a function that you need to apply somewhere, instead of the others guys trying to open a popup in the document.ready or load event. – lolol Jan 15 '13 at 18:52

4 Answers4

3
$(document).ready(function() {
    setTimeout(function() {
        $('#myLink').click();
    }, 3000);
});
Andy
  • 51
  • 2
0

You can use this:

<script>
    $(document).ready(function () { 
        setTimeout(function () {
            ShowModalPopup('dvPopup');
        },3000);
    }); 
</script>

The script will count 3 seconds after the page is rendered and will run the ShowModalPopup('dvPopup')

halfer
  • 19,824
  • 17
  • 99
  • 186
Bertrand
  • 13,540
  • 5
  • 39
  • 48
0

If you are using jQUery you can simply trigger the call on document load like this:

$(function () {
    setTimeout(function () {
        ShowModalPopup('dvPopup');
    }, 3000);
});
Mike Brant
  • 70,514
  • 10
  • 99
  • 103
0
window.onload = function() {
                  setTimeout(foo, 3000); 

                };

function foo()
{
 ShowModalPopup('dvPopup');
}
srijan
  • 1,504
  • 1
  • 13
  • 24