[英]How to close a bootstrap modal popup after downloading a file
I have a popup that uses bootstrap modal. 我有一个使用bootstrap模式的弹出窗口。 The popup allows the user to either download a file or cancel.
弹出窗口允许用户下载文件或取消。 What I want to do is close the popup once the user clicks on the 'Download' button (and the download starts), as it does for the cancel option.
我想要做的是在用户点击“下载”按钮(并开始下载)后关闭弹出窗口,就像取消选项一样。
I tried using data-dismiss on the type submit button for downloading and while that closed it, a download was not initiated. 我尝试在类型提交按钮上使用data-dismiss进行下载,当关闭它时,没有启动下载。
This is how my two buttons look: 这是我的两个按钮的外观:
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Download</button>
<button type="button" class="btn btn=secondary" data-dismiss="modal">Cancel</button>
</div>
Right now when I click on the button, a download starts but the popup remains. 现在,当我点击按钮时,下载开始,但弹出窗口仍然存在。 If I click on Cancel, the popup closes.
如果我单击取消,弹出窗口将关闭。 Can I close after download with something like data-dismiss, or do I need javascript for this?
我可以在下载之后用数据关闭之类的东西关闭,还是我需要javascript?
According to the doc , you can hide your modal with jquery with $('#myModal').modal('hide')
. 根据文档 ,您可以使用
$('#myModal').modal('hide')
使用jquery隐藏模态。 Add an id to your modal and then dismiss it with jquery inside your download function as below: 在模式中添加一个id,然后在下载函数中使用jquery将其解除,如下所示:
function download() {
$('#myModal').modal('hide');
....
....
}
Yes, you have to close the modal using javascript inside the function where you initiate download. 是的,您必须在启动下载的函数内使用javascript关闭模式。 (You can even trigger the clicking of cancel button)
(你甚至可以触发点击取消按钮)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.