diff --git a/Turbolinks/WebView.js b/Turbolinks/WebView.js index 3e39cd6..caccd9b 100644 --- a/Turbolinks/WebView.js +++ b/Turbolinks/WebView.js @@ -54,7 +54,11 @@ // Adapter interface visitProposedToLocationWithAction: function(location, action) { - this.postMessage("visitProposed", { location: location.absoluteURL, action: action }) + if (this.controller.locationIsSamePageAnchor(location)) { + this.controller.scrollToAnchor(location.anchor) + } else { + this.postMessage("visitProposed", { location: location.absoluteURL, action: action }) + } }, visitStarted: function(visit) { diff --git a/TurbolinksDemo/server/lib/turbolinks_demo/views/index.erb b/TurbolinksDemo/server/lib/turbolinks_demo/views/index.erb index 99f4e7d..0163d6c 100644 --- a/TurbolinksDemo/server/lib/turbolinks_demo/views/index.erb +++ b/TurbolinksDemo/server/lib/turbolinks_demo/views/index.erb @@ -6,6 +6,11 @@
  • Trigger an HTTP 404 to see how Turbolinks handles error responses.
  • Visit a protected area to see how to handle an unauthorized session using a separate web view.
  • Load a native view controller to see how to intercept the URL and handle it natively.
  • +
  • Scroll to an element on this page.
  • Follow an external link to open it in Safari.
  • Post a message from JavaScript to see how it can be handled natively.
  • + +
    + Same-page anchor. Back to top. +