Ticket #394 (new defect)
Patch to unbreak the back button when using SmoothScroll
| Reported by: | Steffen | Owned by: | |
|---|---|---|---|
| Type: | defect | Priority: | minor |
| Milestone: | Mootools version 1.3 | Component: | Core |
| Keywords: | smoothscroll back button | Cc: |
Description
Currently when using SmoothScroll? you cannot use your browser´s back button to go back to your previous scroll position in the document. I´ve fixed this with the following patch. It fools the browser by temporarily changing the target´s id so that the browser cannot scroll jump to the target on its own, _but_correctly remembers the current scroll position so that you can use the back button.
I agree that this solution is not very elegant, but it solves this bug and even if you don´t apply it maybe it can serve as an inspiration.
--- mootools-debug.js 2007-08-11 20:24:23.000000000 +0200
+++ mootools-debug.js 2007-08-11 20:24:24.000000000 +0200
@@ -6549,16 +6549,17 @@
var anchor = link.href.substr(location.length);
if (anchor && $(anchor)) this.useLink(link, anchor);
}, this);
- if (!window.webkit419) this.addEvent('onComplete', function(){
- window.location.hash = this.anchor;
- });
},
useLink: function(link, anchor){
- link.addEvent('click', function(event){
+ link.addEvent('click', function(){
this.anchor = anchor;
this.toElement(anchor);
- event.stop();
+ var anchor_el = $(anchor);
+ anchor_el.id += '_';
+ window.setTimeout(function(){
+ anchor_el.id = anchor;
+ }, 0);
}.bindWithEvent(this));
}