问题
So say I have the following code:
window.prompt('Redirecting');
location.href = '/';
(I know this isn't useful code, but wait one sec) I can't figure out how to make it so that prompt doesn't 'freeze' the whole browser so that the redirect is forced to happen. So that in essence what I want is the prompt to come up and immediately for the page to redirect. (without user pressing anything)
I can't seem to find any documentation on how to have a timer on prompt to stop it after a while and/or to stop it from some other method. Anyone have any thoughts?
回答1:
You can not have a timer to close a prompt, alert, confirm, etc.
If you want to do something like that you are going to have to build something using layers in JavaScript. Look at libraries like jQuery UI dialog, YUI's, dojos, or any other library out there.
回答2:
How alert, prompt, etc behave is up to the browser. Mostly, they are fully modal, so they block all input. I'd suggest a framework such as FancyBox to show a popup that isn't modal and isn't under the browser's control.
来源:https://stackoverflow.com/questions/14690438/how-to-redirect-while-prompt-is-still-active