Question

I've have the back and foward buttons working via History.js in both HTML5 and HTML4 browsers.

I'm now attempting to add bookmark support by parsing the url, and loading the content in the querystring. The code I normally use to do this is:

var urlParams = {};
            (function () {
            var match,
                pl     = /\+/g,  
                search = /([^&=]+)=?([^&]*)/g,
                decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
                query  = window.location.search.substring(1);

            while (match = search.exec(query))
            urlParams[decode(match[1])] = decode(match[2]);
            })();  

This works great for the HTML5, but obviously does not work for the HTML4. Whats a good way to parse the hash in HTML4, and the substring in HTML5?

Était-ce utile?

La solution

found a solution on this page: https://getsatisfaction.com/balupton/topics/history_js_and_retrieving_state_from_a_url

"You can use this function however from one of my utility projects called jQuery Sparkle to do what you need: https://github.com/balupton/jquery-sparkle/blob/master/scripts/resources/core.string.js#L164

So you would do this:

var State = History.getState(), dataQuery = State.url. queryStringToJSON();"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top