Skip to content Skip to sidebar Skip to footer

Javascript: How To Open A Page Then Wait For Few Seconds Open Another Page In The Same Window

I tried to open an url in a window then wait for few seconds and opened another url in the same window. But the script doesn't work. When run it gives a blank window. I am new in J

Solution 1:

You could give this a try:

<scripttype="text/javascript">functiondef()
{
my_window.location="http://www.yahoo.com";
setTimeout("abc()", 3000);
}

functionabc()
{
alert("Delayed 3 seconds");
my_window.location="http://www.youtube.com";
}
</script>

Solution 2:

In general, it is inadvisable to use blocking loops in javascript. In your case, you would want to use something like setTimeout or setInterval. This code should work:

var win = window.open("http://foo.com");
setTimeout(function(){
    win.location = "http://bar.com";
    setTimeout(function(){
        win.close();
    }, 10000);
}, 10000);

Solution 3:

Tested and this one works but the popup blocker appears

<!DOCTYPE html><html><head><script>functionopen_win() 
        {
            setTimeout("go('http://www.yahoo.com')", 5000);

            setTimeout("go('http://www.youtube.com')", 10000);

        }

        functiongo(url){
            window.open(url);
        }
    </script></head><body><form><inputtype="button"value="Open Win"onclick="open_win()"></form></body></html>

Solution 4:

UPDATED

I wrote the following HTML and it worked fine for me showing what is required in your post:

<html><head><scriptlanguage="JavaScript"type="text/javascript">var my_window;

        functionOpenWin()
        {
            my_window=window.open("http://www.yahoo.com", "_blank", "resizable=yes, scrollbars=yes, titlebar=yes, width=1000, height=800, top=10, left=10");
            setTimeout("GoUrl('http://www.youtube.com')", 10000);
        }
        functionGoUrl(Url)
        {
            my_window.location=Url;
        }
        </script></head><body><buttononclick="OpenWin()">Open Window</button></body></html>

Post a Comment for "Javascript: How To Open A Page Then Wait For Few Seconds Open Another Page In The Same Window"