Javascript 引导模式关闭问题

Javascript 引导模式关闭问题,javascript,angularjs,twitter-bootstrap,bootstrap-modal,ngroute,Javascript,Angularjs,Twitter Bootstrap,Bootstrap Modal,Ngroute,我正在努力解决我的模式中的bug。我使用的是Bootstrap,Angular和ng-Route。我最近注意到,在mobile(然后在桌面上)上,当我用modal打开按钮按下后退按钮时,它会留下一个灰色覆盖层,您无法单击任何内容。因此,我发现部分解决问题的解决方案是添加以下脚本: $(".modal").on("shown.bs.modal", function() { // any time a modal is shown var urlReplace = "#/" + $(t

我正在努力解决我的
模式
中的bug。我使用的是
Bootstrap
Angular
ng-Route
。我最近注意到,在
mobile
(然后在桌面上)上,当我用
modal
打开按钮按下后退按钮时,它会留下一个灰色覆盖层,您无法
单击任何内容。因此,我发现部分解决问题的解决方案是添加以下脚本:

$(".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');
    });
这非常有效,然后用户
按下
后退按钮
,但是当用户通过单击模式外部或点击escape关闭
模式
时,URL替换仍保留在
浏览器
地址栏中我想让它在关闭
模式时变回上一个模式。

如果该问题无法解决,我至少希望修复另一个问题,即:当用户通过单击外部或按escape关闭
模式
时,
urlReplace
仍保留在
浏览器
地址中,这很好,但当用户转到
时,单击
我的
导航中的链接bar
它不会将他们带到链接,它会转到一个空白页,地址栏中仍有
URLEPLACE
,然后我可以
再次单击
nav bar
中的链接,它会转到正确的链接,我觉得奇怪,不知道如何解决此问题


任何关于这方面的想法或见解都将非常棒

您可以添加一个处理程序来监视模式关闭事件,然后在删除哈希的情况下推送一个新的历史记录:

$(".modal").on("hidden.bs.modal", function()  { // any time a modal is hidden
    var urlReplace = window.location.toString().split('#', 1)[0]
    history.pushState(null, null, urlReplace); // push url without the hash as new history item
});

您可以添加一个处理程序来监视模式关闭事件,然后在删除哈希的情况下推送一个新的历史记录:

$(".modal").on("hidden.bs.modal", function()  { // any time a modal is hidden
    var urlReplace = window.location.toString().split('#', 1)[0]
    history.pushState(null, null, urlReplace); // push url without the hash as new history item
});

非常感谢你!我觉得有些奇怪的事情正在发生,但它只需要在关闭模式时输入正确的url,我在导航中单击的链接现在正常工作!非常感谢你!我觉得有些奇怪的事情正在发生,但它只需要在关闭模式时输入正确的url,我在导航中单击的链接现在正常工作!