如何控制在导航栏中显示的jquery mobile中的url

Posted

技术标签:

【中文标题】如何控制在导航栏中显示的jquery mobile中的url【英文标题】:How to control url in jquery mobile which displayed in navigator bar 【发布时间】:2017-06-21 15:12:18 【问题描述】:

我正在开发一个只能在一个静态 url 下工作的 jQuery Mobile 应用程序,它可能会调用单页应用程序。

当我在mobileinit 事件中使用$.mobile.changePage.defaults.changeHash = false 时,点击导航到其他页面的链接效果很好,网址永远不会改变。但是当我输入带有hashTag的完整url时,url会发生变化。例如,在导航栏中输入http://www.example.com/home/index#catelog/lists之类的url,url会变成http://www.example.com/catelog/lists。看来$.mobile.changePage.defaults.changeHash = false在这种情况下不起作用.

那么,如何控制 jQuery Mobile 仍然显示http://www.example.com/home/index

【问题讨论】:

【参考方案1】:

在头上:

<script type="application/javascript" src="js/libs/jquery-1.11.2.min.js"></script>
<script>
    window.addEventListener('DOMContentLoaded', function() 
        if (window.history && window.history.pushState)
            window.history.pushState('', '', window.location.pathname) 
        else
            window.location.href = window.location.href.replace(/#.*$/, '#'); 
    , true);
    $(document).on('mobileinit', function () 
        // If you need it:
        $.mobile.hashListeningEnabled = false;
        $.mobile.pushStateEnabled = false;
        $.mobile.changePage.defaults.changeHash = false;
    
</script>
<script type="application/javascript" src="js/libs/jquery.mobile-1.4.5.min.js"></script>

【讨论】:

以上是关于如何控制在导航栏中显示的jquery mobile中的url的主要内容,如果未能解决你的问题,请参考以下文章

jQuery Mobile 导航栏

jQuery Mobile 导航栏

如何在导航栏中添加多个栏按钮

如何从导航栏中删除 UIPageControl?

jQuery Mobile 弹出页面导航后不显示,仅在硬刷新或返回同一页面后显示

如何删除 jQuery Mobile 导航图标的圆形容器?