diff --git a/boot/boot.js b/boot/boot.js index cfc75816f..c08acdcac 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -202,6 +202,14 @@ $tw.utils.htmlDecode = function(s) { return s.toString().replace(/</mg,"<").replace(/ /mg,"\xA0").replace(/>/mg,">").replace(/"/mg,"\"").replace(/&/mg,"&"); }; +/* +Get the browser location.hash. We don't use location.hash because of the way that Firefox auto-urldecodes it (see http://stackoverflow.com/questions/1703552/encoding-of-window-location-hash) +*/ +$tw.utils.getLocationHash = function() { + var parts = window.location.href.split('#'); + return "#" + (parts.length > 1 ? parts[1] : ""); +}; + /* Pad a string to a given length with "0"s. Length defaults to 2 */ @@ -1627,7 +1635,7 @@ $tw.boot.startup = function(options) { if(location.hash === "#:safe") { $tw.safeMode = true; } else { - $tw.locationHash = location.hash; + $tw.locationHash = $tw.utils.getLocationHash(); } } // Initialise some more $tw properties diff --git a/core/modules/startup/story.js b/core/modules/startup/story.js index 2634379c5..df54fe827 100644 --- a/core/modules/startup/story.js +++ b/core/modules/startup/story.js @@ -36,8 +36,9 @@ exports.startup = function() { }); // Listen for changes to the browser location hash window.addEventListener("hashchange",function() { - if(window.location.hash !== $tw.locationHash) { - $tw.locationHash = window.location.hash; + var hash = $tw.utils.getLocationHash(); + if(hash !== $tw.locationHash) { + $tw.locationHash = hash; openStartupTiddlers({defaultToCurrentStory: true}); } },false) @@ -104,8 +105,11 @@ function updateLocationHash() { } $tw.locationHash = "#" + encodeURIComponent(targetTiddler) + ":" + encodeURIComponent($tw.utils.stringifyList(storyList)); // Only change the location hash if we must, thus avoiding unnecessary onhashchange events - if(window.location.hash !== $tw.locationHash) { +// console.log("Testing",$tw.utils.getLocationHash(),$tw.locationHash) + if($tw.utils.getLocationHash() !== $tw.locationHash) { window.location.hash = $tw.locationHash; +console.log("Just set",$tw.locationHash,$tw.utils.getLocationHash()) + } }