# character in url of jquery mobile page

吃可爱长大的小学妹 提交于 2020-01-14 14:29:09

问题


Why is it that when I visit my jQuery mobile page, lets say page.php it shows up fine, but when I visit the same page page.php#someDetailsHere it just shows a white page? And how can I fix this?

I use a third party app that redirects to my webpage with the # added to the url..


回答1:


Edit: I stepped through your page to see what was going on.

Your grief is caused by jQuery Mobile. When the page loads, it detects this as an "page change", and because jQuery Mobile uses the hash (#) to emulate the back-button for AJAX requests, it also has some special handling for pages that it sees are loaded with a hash.

The bottom line is that it sees a page load, decides it should "reject" it, and prevents anything further from happening.

My guess is that the jQuery Mobile team didn't expect anyone to load a mobile page with a hash on init, since the code seems to assume that the first load of the page will not have one.

To follow this yourself, set a breakpoint in the function isEmbeddedPage in jquery.mobile-1.0.min.css.

A possible solution would be to somehow prevent the jQuery Mobile code from running when the page initially loads. This might break other stuff that jQuery Mobile provides, though.




回答2:


As says It turns out jQM parses hashes for its own purposes and just freezes if it can't make sense of them on load (unnecessarily aggressive behaviour if you ask me, they should at least fire a custom event — although there is a high priority issue reported for it on GitHub).

One solution is to disable jQM's hash processing: before DOM ready, execute the following:

$.mobile.hashListeningEnabled = false;

Note this will necessarily break any functional reliance on jQM's history polyfill on browsers that don't support history pushState (IE etc).



来源:https://stackoverflow.com/questions/8812463/character-in-url-of-jquery-mobile-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!