turbolinks / turbolinks-ios

Native iOS adapter for building hybrid apps with Turbolinks 5
MIT License
881 stars 92 forks source link

Page anchors open in Safari instead of scrolling to anchor #52

Closed elsurudo closed 8 years ago

elsurudo commented 8 years ago

For example: <a class="office-address" data-turbolinks="false" href="#location">123 Fake St., Springfield</a>

Somewhere below is: <a name="location"></a>

thetizzo commented 8 years ago

I could be wrong about this but the href in the first link refers to something with an id of location and the second link just has a name of location.

Having the second link look like this may fix it: <a id="location"></a>

elsurudo commented 8 years ago

No, the name method is the correct way of doing it. Maybe not an authoritative source, but see: http://www.echoecho.com/htmllinks08.htm

exalted commented 8 years ago

Apparently name is invalid for a in HTML5: http://www.w3schools.com/tags/att_a_name.asp

elsurudo commented 8 years ago

Huh, well I’ll be damned. Thanks for the info. I will try using the ID and see if it makes a difference with turbolinks.

On Sep 11, 2016, at 1:47 PM, Ali Servet Donmez notifications@github.com wrote:

Apparently name is invalid for a in HTML5: http://www.w3schools.com/tags/att_a_name.asp http://www.w3schools.com/tags/att_a_name.asp — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/turbolinks/turbolinks-ios/issues/52#issuecomment-246176165, or mute the thread https://github.com/notifications/unsubscribe-auth/AADELwsA62gVIBpa7OBNCekT95i-E2cOks5qo-pLgaJpZM4JZblT.

exalted commented 8 years ago

@elsurudo am glad if it was helpful. Btw, I have no idea if this has anything related to turbolinks or Safari on iOS. 🍻

zachwaugh commented 8 years ago

Thanks for the bug report! Confirmed this is currently a limitation of Turbolinks, there's more info in this thread about how Turbolinks does/should handle anchor links - https://github.com/turbolinks/turbolinks/issues/75.

The reason it's opening in Safari is when data-turbolinks="false" is set, Turbolinks ignores the link and it goes through WKNavigationDelegate's webView:decidePolicyForNavigationAction:decisionHandler: method, and the default behavior is to open in Safari. If you don't include the data-turbolinks="false", it will hit sessionDidProposeVisit() method. You could handle it yourself in either of those methods by checking the URL and taking appropriate action, but your best bet is to probably to intercept it and handle in JavaScript.