twitter-bootstrap 在 Bootstrap Modal 上打开 URL 关闭
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20580978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open URL on Bootstrap Modal close
提问by Michael Reiland
Maybe I'm brain dead here, but I'm trying to do what seems should be an easy thing.
也许我在这里脑死了,但我正在努力做看起来应该很容易的事情。
I am using Bootstrap to open a modal on page load depending on the value of specific variables. This all works great. However, when the modal opens and the user clicks ok (presumably after reading the info text), I want to page to redirect to a new page. I can't seem to figure out how to do this.
我正在使用 Bootstrap 根据特定变量的值在页面加载时打开一个模式。这一切都很好。但是,当模式打开并且用户单击确定时(大概是在阅读信息文本后),我想页面重定向到新页面。我似乎无法弄清楚如何做到这一点。
Any info on how to do
有关如何操作的任何信息
回答by Kna?is
$(".modal").on("hidden.bs.modal", function () {
window.location = "your-url";
});
http://getbootstrap.com/javascript/#modals-usage
http://getbootstrap.com/javascript/#modals-usage
You could also (and that is probably a better option) add a onclickhandler to the button that the user has to click (because the hidden.bs.modalevent also fires when the user closes the modal by pressing Escor clicking the xbutton.
您还可以(这可能是更好的选择)onclick向用户必须单击的按钮添加一个处理程序(因为hidden.bs.modal当用户通过按下Esc或单击x按钮关闭模态时也会触发该事件。
回答by Zim
Along the lines of @Knagis additional option, you can use onclickto change the window.location, and the data-dismiss=modalattribute in the same link..
沿着@Knagis 附加选项的行,您可以使用onclick更改window.location 和data-dismiss=modal同一链接中的属性。
<a href="" data-dismiss="modal" onclick="javascript:window.location='http://google.com'">Visit Google.</a>
回答by M P
it also dismiss the modal , modal should be dismissed after 10-20 seconds or manualy by closing it , is it possible .
它还关闭模态,模态应该在 10-20 秒后关闭或手动关闭它,是否可能。

