Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Bad URLs with hashes are not gracefully handled #4119

Closed
jefflembeck opened this issue Apr 19, 2012 · 5 comments
Closed

Bad URLs with hashes are not gracefully handled #4119

jefflembeck opened this issue Apr 19, 2012 · 5 comments

Comments

@jefflembeck
Copy link
Contributor

I'm not sure if this is by design or not, but

http://jquerymobile.com/demos/1.1.0/##

Is a decent example of this.

I'd expect the page to just load at this point, instead it freezes with a JS error. This is likely caused by the way that hash changes are handled.

@toddparker
Copy link
Contributor

Yeah, this is a bug for sure. In fact, an empty hash should probably be ignored too (/#), right now it navigate you to the root.

@ghost ghost assigned johnbender Apr 20, 2012
@barneycarroll
Copy link

Double hash, or any form of bad URL, is not necessary — any (legitimate) hash will break init, eg:

http://jquerymobile.com/demos/1.1.0/#jqm-logo

From my execution, no errors are thrown, and no custom events are fired — the page rests in a loading state and initialisation is frozen.

EDIT: You can prevent this behaviour by executing jQuery.mobile.hashListeningEnabled = false; before DOM ready. But you shouldn't have to chose between a staple of native web behaviour & jQM history management.

@frequent
Copy link
Contributor

I'm also running across this when trying to load deeplinks using my multiview plugin, because by default my some.html#nested_page_ID will also be a bad URL. I have patched my JQM like this to fix it for me:

 // also check for panel subpages
 if ( !$.mobile.hashListeningEnabled || !$.mobile.path.stripHash( location.hash ) || $( window.location.hash ).closest('div:jqmData(role="panel")').length > 0 ) {              
            // store hash, retrieve inside multiview
            $('html').data("deep", window.location.hash);
            // back to JQM
            $.mobile.changePage( $.mobile.firstPage, { transition: "none", reverse: true, changeHash: false, fromHashChange: true } );
        }

I'm trying to get by without touching JQM.js, so in case you are adding some more logic and are open for wishes... I would also like a custom event such as "loadFirstPage" to tap into.

I guess once you start thinking about supporting anchor tags, you will need some more logic here anyway, because all anchor tags will be bad as of now. What do you think?

@ghost ghost assigned gseguin Apr 26, 2012
@frequent
Copy link
Contributor

frequent commented May 4, 2012

@gseguin

Thinking more about a loadFirstPage event.... this would also be very useful for deeplinks to artifical hashtags. Say I have a page some.html, in which I'm updating content via Ajax.

I would like to reflect the updated page by changing the hashtag, but I can't because all deeplinks to this page ala some.html#new_content will break, because the page isn't there and I'm missing an event to tap into the first page being loaded to redirect to the actual page and fire an Ajax call to update the content.

No problem on the 2nd page with pagebeforechange, but on the first page, this does not fire, does it?

If I could do:

$(document).on('firstpageload', ':jqmData(role="page")', function(e, data) {
    if ( if the deeplink requested is NOT in the document ) {
        e.preventDefault();
        // do something else
        } 
    })

@jefflembeck
Copy link
Contributor Author

Just to note, based on this proposed fix: when hash listening is enabled, things still break.

hpbuniat pushed a commit to hpbuniat/jquery-mobile that referenced this issue May 26, 2012
Fixes jquery-archive#4119 - Bad URLs with hashes are not gracefully handled
jasondscott pushed a commit that referenced this issue May 29, 2012
Fixes issue #4119
Added regex test to see if hash is valid and if a page with that id
exists, if not load the first page.

Added unit tests for isHashValid
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants