I am implementing a website that dynamically configures its URLs using History.js when new sections are uploaded to the main page via ajax.
This seems to work well, but there is a problem with the hash section in the URL that History.js creates as a backup in Internet Explorer.
Here are examples of page links created using jquery:
function connect_browse_buttons(){ $('.browselink').each(function(){ $(this).click(function(){ var action = $(this).attr('name'); action = action.substring( ('action_browse').length ); browsetype = action; if (isIE){
The .htaccess file redirects any URLs, such as http://example.com/public/category_a to http://example.com , where javascript parses the URL and loads the corresponding section through ajax requests in the changeState handler.
Javascript validates URLs such as
http:
And for equivalent fallback URLs created in Internet Explorer, i.e.
http://example.com/
Everything works fine - So:
In Firefox , if I open the site in the root of the site, http://example.com and click on the link above, the content is loaded (in the changeState handler), and the URL is set in History.pushState as:
http:
If I then click on another link, the URL is set as, for example:
http:
In IE , if I open the site in the root of the site and click the link as indicated above, the content is loaded and the URL is set with a hash like:
http://example.com/
If I then click on the following link, the URL is set as:
http://example.com/
The problem occurs when I open a page in IE that has been bookmarked in Firefox and does not have a hash in the URL. Take our usual example:
http:
If I open this url directly in IE, through a bookmark or by inserting a URL into the address bar of the browser, .htaccess will be redirected successfully, the url will be parsed OK by the js file and the contents will be loaded. However, now if I click on the category_b link, the url is set in History.pushState for:
http://example.com/public/category_a#./category_b
I really wanted to set the URL as:
http://example.com/
However, History.js seems to take the entire previous url as the base url for subsequent pushStates. I tried setting absolute URLs in History.pushState, but to no avail. As you can see in the above code block, I have an IE specific pushState statement. I tried to configure it differently. How can I find out pushState history to find out:
http:
as the base portion of the url to which the hash section should be attached? Or is there a better way to approach this than the one described above?