Skip to content Skip to sidebar Skip to footer

Javascript Redirect With Hash Tag

I have implemented my website's search results with AJAX, using History.js. For HTML5 browsers, I have URLs like http://example.com/search/X6a2/3, which, in browsers not supporting

Solution 1:

This seems to work for me. Are you sure window.replace is the problem?

var href = "http://example.com/search/X6a2/3";
var idx = href.indexOf('search', 0);
var new_href = href.slice(0,idx+7) + "#" + href.slice(idx+7);

alert(new_href);
window.location.replace(new_href);

Post a Comment for "Javascript Redirect With Hash Tag"