阻止Jquery Mobile处理URL哈希? [英] Preventing Jquery Mobile from processing URL hash?

查看:93
本文介绍了阻止Jquery Mobile处理URL哈希?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在现有的Web应用程序中使用Jquery Mobile.问题是,jQuery Mobile正在处理所有URL哈希.例如:

I'm using Jquery Mobile in an existing web application. The problem is, Jquery Mobile is processing all URL hashes. For example:

mysite.com/#foo

在这里,哈希'foo'被发送到Jquery Mobile,并且正在处理它,而不是让我的非jquery mobile代码对其进行处理.

Here, the hash 'foo' is being sent to Jquery Mobile, and it is processing it, instead of letting my non-jquery mobile code process it.

是否可以防止Jquery Mobile干扰url哈希?

Is it possible to prevent Jquery Mobile from interfering with the url hash?

推荐答案

jQuery Mobile的默认行为是监听 hashchange 事件并仅在启用 Ajax 时更新 URL哈希以处理页面的历史记录.

The default behavior of jQuery Mobile is listening to hashchange event and updates URL hash in order to handle history of pages, only when Ajax is enabled.

要处理页面链接,第一次运行时应禁用changeHashhashListeningEnabled属性 全局设置 .

To handle pages linking, both changeHash and hashListeningEnabled properties should be disabled on first run mobileinit. This event fires before loading jQuery Mobile library and .ready(); it should be used to change Global Settings of the framework.

<script src="jquery.js"></script>
<script>
  $(document).on("mobileinit", function () {
    $.extend( $.mobile, { 
      changePage.defaults.changeHash: false,
      hashListeningEnabled: false
    });
 });
</script>
<script src="jquery.mobile.js"></script>

这篇关于阻止Jquery Mobile处理URL哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆