farhangdon farhangdon - 7 months ago 15
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

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.