askemottelson
askemottelson

Reputation: 159

# character in url of jquery mobile page

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..

Upvotes: 3

Views: 753

Answers (2)

Barney
Barney

Reputation: 16466

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).

Upvotes: 1

Shalom Craimer
Shalom Craimer

Reputation: 21469

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.

Upvotes: 2

Related Questions