【发布时间】:2023-03-31 14:05:02
【问题描述】:
我正在尝试解决我的modal 中的错误。我正在使用Bootstrap、Angular 和ng-Route。我最近在mobile(然后在桌面)上注意到,当我在modal 打开的情况下按下后退按钮时,它会留下一个灰色的覆盖层,你不能click 任何东西。所以我发现部分解决问题的解决方案是添加这个脚本:
$(".modal").on("shown.bs.modal", function() { // any time a modal is shown
var urlReplace = "#/" + $(this).attr('id'); // make the hash the id of the modal shown
history.pushState(null, null, urlReplace); // push state that hash into the url
});
// If a pushstate has previously happened and the back button is clicked, hide any modals.
$(window).on('popstate', function() {
$(".modal").modal('hide');
});
这对用户 presses 和 back button 非常有效,但是当用户通过单击模式外部或点击转义关闭 modal 时,urlReplace 仍保留在 browser 地址栏中。 我想让它在modal 关闭时恢复到以前的状态。
如果该问题无法解决,我至少希望解决另一个问题,即:当用户通过单击外部或点击转义关闭modal 时,urlReplace 仍保留在browser 地址中很好,但是当用户然后转到click 我的nav bar 中的链接时,它不会将他们带到链接它转到一个空白页面,urlReplace 仍在地址栏中,然后我可以@987654341 @@nav bar 中的链接,它会转到正确的链接,我觉得很奇怪,不知道如何解决这个问题。
对此的任何想法或见解都会很棒!
【问题讨论】:
标签: javascript angularjs twitter-bootstrap bootstrap-modal ngroute