How to redirect while prompt is still active?

自古美人都是妖i 提交于 2019-12-24 04:45:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!