I have an alert box that pops up, warning the user that they will be redirected soon. However, redirection only happens after they click OK.
I want redirection to happen while the alert box is popped up, not after . Also, there should also be enough time for the user to read the alert in the first place (I allowed 2.5s). Any advice?
Code below:
setTimeout("redir()", 2500);
alert("You are being redirected.");
function redir () {
window.location = "target.php";
}
The standard alert box halts page execution, so you can't redirect while it's showing. The user has to first press ok. You have to come up with a custom message if you want this behavior.
You can have a look at a library called toastR https://github.com/CodeSeven/toastr
It lets you define callbacks for when a message is shown/hidden.
You could use a dialog box instead of the native alert box. For example, jQuery UI: http://jqueryui.com/dialog/
don't use an alert. display a note via a div or span on top of the page... you aren't waiting for their input/acceptance of the fact they are being redirected.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.