baker icon indicating copy to clipboard operation
baker copied to clipboard

Links to anchor id/tags are ignored

Open aldriq opened this issue 15 years ago • 11 comments

While building a table of contents I've been unable to get links to id sections/anchors to work. In all my tries the link simply takes me to the top of the target page.

Basically my link is <a href="03.html#sec2">, and for the anchor I've tried both the HTML5 way <h2 id="sec2">Title</h2> and the old way <a id="sec2" name="sec2">. They both work in Safari but seem to be ignored in Baker.

aldriq avatar Feb 24 '11 19:02 aldriq

This is indeed a bug, we'll check! ;)

folletto avatar Feb 24 '11 20:02 folletto

Added support for links destination anchor. Closed by d9f31ea4909473c3f84e7c0d126b49ec2ca6e133

Xm4s avatar Mar 11 '11 21:03 Xm4s

The new code sorts it out nicely. The only thing I had to change was "document.getElementsByName('%@')[0].offsetTop" with "document.getElementById('%@').offsetTop" in handleAnchor so it works with id attributes (I'd already built my table of contents based on ids). I guess both id and name anchors should be handled.

Thank you very much!

aldriq avatar Mar 12 '11 13:03 aldriq

Thank you aldriq for pointing this out! I'll commit an improved method as soon as possible :)

Xm4s avatar Mar 12 '11 14:03 Xm4s

I've commited the improved method for handling anchors, now it works for both id and name attributes :)

Be aware that there seems to be an issue with UIWebView: click on link seems to pass from "shouldStartLoadWithRequest" only once (ref: http://stackoverflow.com/questions/1840355/uiwebview-shouldstartloadwithrequest-only-called-once). Click on another link or reload the page reset this strange behavior.

So, while in Baker we handle hash reference to both id and name attributes now (as W3C standard), the second click on a link is handled by the UIWebView itself, which doesn't seems to handle anchor to name attributes (only outside Safari Mobile... there it all works perfectly).

I'll look more into this issue, for now I suggest to point hash reference to tag with the id attribute set.

Thank you again aldriq, your suggestion has proved really useful

Xm4s avatar Mar 13 '11 13:03 Xm4s

Thanks for all the thorough research, I never thought this would open such a little can of worms...

aldriq avatar Mar 14 '11 00:03 aldriq

Can we get a quick example how to use anchors in Baker? Right now I'm using <a name="zoom01" id="zoom01" href="zoom/zoom-001.html"> to link to a page and <a href="../001.html#zoom01"> to go back. It's not working in Baker (it does in Safari), I guess I misread something :)

danielbenjamins avatar Oct 02 '11 13:10 danielbenjamins

Hi!

A quick example of an anchor ... let's see ...

• put a link link to page 5 in your page 001.html. • in the page 005.html assign the id="my-anchor-1" to an element. • click on the link on page 001.html and the book should go to page 005.html and then scroll down to you element id="my-anchor-1"

That's it, nothing more :)

Xm4s avatar Oct 10 '11 22:10 Xm4s

Thanks, I'll try this later if I still need it :)

danielbenjamins avatar Oct 11 '11 08:10 danielbenjamins

We did some additional tests:

  1. Links from a page of the book to a page of the book with anchor, goes there correctly.
  2. Links from a page inside an iframe to a page of the book with anchor, goes there correctly.
  3. Links from a page of the book to a page outside the book with an anchor, goes there correctly.
  4. Links from a page outside of the book (opened like point 3 above for example) to the page previously there, goes there correctly.
  5. Links from a page outside of the book (opened like point 3 above for example) to a different page inside the book, goes there correctly.

We have enabled the items 3, 4, 5 above with the recent commit to try address the issues you noted. :)

I think that should cover all the basic anchor situations. :)

folletto avatar Oct 16 '11 14:10 folletto

Hi - I'm attempting to do something like enable your item "1" in your list of 5 items above:

  1. Links from a page of the book to a page of the book with anchor, goes there correctly.

Without this, I am not able to have the page and book behavior I'm looking for, which is:

a) Tap an anchor link from a TOC page to go to a horizontal anchor in the destination page.

b) Have this destination page reside in the book.json manifest.

I am able to of course get the horizontal anchor to work in a page not included in the book.json list, since this forces the book app to open this page in a UIWebView, which obeys horizontal anchor links. However, what this means is that this new page basically replaces my TOC page, and thus will swipe left and right to the pages consecutively before / after the TOC page - not its own pages since it doesn't exist in the book.json chronology.

It would be great to be able to horizontally anchor on a page and still have this page swipe left or right to its own consecutive pages.

I tried to create a goRightInPage pragma mark, and use this to modify the handleAnchor mark, but it didn't work.

Any suggestions?

CatherineEng avatar Sep 09 '12 08:09 CatherineEng