How to add 5 second delay to onClick window.open?

12,575

Your parenthese and quotes aren't balanced. Try:

onclick="setTimeout('window.open(\'http://google.com\')', 5000);"
Share:
12,575
badkitty72
Author by

badkitty72

Updated on June 04, 2022

Comments

  • badkitty72
    badkitty72 almost 2 years

    I have a code that hides multiple div's with a sliding action with one click on a text link. I need to add an open.window to the text link also, that will open a url in another window after a few seconds delay.

    So with one click I want to hide a group of div's, and open a url in another window after a short delay, so that the sliding action can be seen before the url is opened.

    I have this code that works to hide the div's with sliding action ...

    $("#hide-content").click(function () {
    $(".otherContainers").hide('slide',{direction: "right"}, 1000);
    });
    

    And this for the text link ....

    <div id="hide-content"><a href="#" class="showHideContent" style="text-decoration:none" onclick="window.open('http://google.com')">hide and visit</a>
    </div>
    

    I've tried adding a delay with this but it's not working ...

    onclick="setTimeout('window.open(\'http://google.com');'5000;"
    

    Any ideas? Thanks!

    Here's a Fiddle http://jsfiddle.net/eeyipes/Jf6wM/13/