farhangdon farhangdon - 2 years ago 81
HTML Question

Loading webpage after some time ASP.net using Javascript

It seems a duplicate but Its taken a lot of time still causing some problem. Kindly someone point out what I am doing wrong.

I have a button, when I click it JS function show() is called

<input type="button" onclick="show()" value="Add to Cart">

The javascript code is below

function show() {

document.getElementById("loadingDiv").style.display = "block";

setTimeout('Redirect()', 2000);
function Redirect() {
location.href = 'Index.aspx';


The div is set to block properly but the page never redirects. Not sure whats the issue.

Answer Source

You need to remove the brackets and the single quotes when you call the redirect function.

setTimeout(Redirect, 2000);

Here is the documentation for the setTimeout function.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download