location.replace
location.replace
I have a page with a table. When I click on a row, I display the <div> that's associated with the row and I change the URL hash part so it's bookmarkable. This part works fine.
I don't want that clicking on rows generates a huge useless browser history so I'm using
document.location.replace to change the hash. The hash is changed successfully but the no-history part only works in Firefox: all other browsers (IE6, IE7, Opera, Chrome...) add a new history entry on every click.
What's driving me crazy is that
I know that document.location.replace does work in Internet Explorer. I have a simple test case that proves it:
-
<!DOCTYPE html>
<title>location.replace should not create new history object</title>
<p><button onclick="location.replace('#test');">Set #test hash</button>
<p>#test should appear at the end of the URI but you should not be able to go to this page without #test as it should not create a new history object.
So... Why is this third-party snippet working fine and my code is not?
-
window.previousRow = null;
$("table#rows tbody tr[id^=row-]").click(function(){
var clickedRow = $(this);
if( !clickedRow.data("id") ){
clickedRow.data("id", clickedRow.attr("id").match(/^row-(\d+)$/i)[1]);
clickedRow.data("relatedData", $("div#relatedData-" + clickedRow.data("id")));
}
if( window.previousRow==null || window.previousRow.attr("id")!="row-" + clickedRow.data("id") ){
clickedRow.addClass("res");
if( window.previousRow != null){
window.previousRow.removeClass("res");
window.previousRow.data("relatedData").fadeOut("normal", function(){
clickedRow.data("relatedData").fadeIn("normal");
});
}else{
clickedRow.data("relatedData").fadeIn("normal");
}
window.previousRow = clickedRow;
// ?????
document.location.replace("#" + clickedRow.attr("id"));
}
});
There aren't any other document.location statements in the rest of the page scripts.