简体   繁体   English

如何防止jquery-mobile中的哈希更改

[英]How to prevent hash changes in jquery-mobile

I have a web site which is populated with articles. 我有一个填充文章的网站。 Clicking on an article takes you to a page and that's basically it. 单击文章会带您进入页面,基本上就是这样。 The problem is that I want to use jquery-mobile and since I pasted it into the head of my files: 问题是我想使用jquery-mobile,因为我将其粘贴到了文件的开头:

<script type="text/javascript" src="scripts/jquery.js"></script>
<script>
    $(document).on("mobileinit", function () {
        $.mobile.changePage("#index", {transition: "slide",reverse: true,changeHash: false});
    });
</script>
<script src="scripts/jquery.mobile.js"></script>

,linking the user to the articleDetail page doesn't work anymore. ,将用户链接到articleDetail页面不再起作用。 I saw that the URL doesn't accept the hashtag sign (#). 我看到该网址不接受井号(#)。

For example: 例如:

<a href="www.myPage.com/#detail/e98eee7e-5032-4d16-8c69-a441af018b8b"</a>

I expect a user to be redirected to this page with that exact same path, but jquery-mobile changes it to: 我希望用户使用完全相同的路径重定向到此页面,但是jquery-mobile将其更改为:

www.myPage.com/detail/e98eee7e-5032-4d16-8c69-a441af018b8b www.myPage.com/detail/e98eee7e-5032-4d16-8c69-a441af018b8b

and because of that nothing happens. 因此,什么也没发生。 I only get an output in the console: 我只在控制台中得到一个输出:

GET www.myPage.com/detail/e98eee7e-5032-4d16-8c69-a441af018b8b 404 (Not Found) GET www.myPage.com/detail/e98eee7e-5032-4d16-8c69-a441af018b8b 404(未找到)

Please help! 请帮忙!

Include these functions in your script: 在脚本中包括以下功能:

$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;

This is defined by jquery mobile to handle hash enabled links 这是由jquery mobile定义的,用于处理启用哈希的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM