Welcome to the in5 Answer Exchange! This a place to get answers about in5 (InDesign to HTML5) and make requests.
0 votes
I have the custom menu with several buttons. I want to link this buttons to some pages. Is it possible make link not to page number, but to the bookmark?
related to an answer for: Custom CSS navigation - links to pages
in how_to by (290 points)
  

2 Answers

+1 vote
 
Best answer

Here's one way to do it with JavaScript code (jQuery).

function goToBookmark(bname){
window.top.nav.to($("[data-bookmarks*='"+bname+"']").index()+1);
}

/*example usage*/
gotoBookmark("tocPage");

by (197k points)
selected by
I don't understand this code.

What this part do?

{window.top.nav.to($("[data-bookmarks*='"+bname+"']").index()+1);
}

especially that part .index()+1);

Should I have this kind of code for bookmark "mission"

$('#mission').on("click", function goToBookmark(mission){
        window.top.nav.to($("[data-bookmarks*='"+mission+"']").index()+1);
        });
nav.to is a function that in5 creates & uses for navigation. nav.to(1) takes you to the 1st page.
window.top ensures that the added code works if its nested in an iframe somewhere.

Bookmarks are stored in the data-bookmarks attribute. The code searches for the string in the bookmark name.

index() gets the position of the page in the document, but it's zero-based, so add a 1 to work with the nav.to function.

There are several issues with the code in your comment. Use this instead:

function goToBookmark(bname){
   window.top.nav.to($("[data-bookmarks*='" + bname + "']").index()+1);
}

$('#mission').click(function(){ goToBookmark('mission'); });
So, "bname" - is variable? I shouldn't rewrite it with my bookmark?
Great! It is works.
Yes, bname is a variable. It's written when you call the function: goToBookmark('mission');
Is the data-bookmarks attribute still being generated? (can't seem to find it in v2.8.10 output)
Yes, so long as you attach something (or select one of the append options) in the Resources section of the in5 dialog.

Otherwise it is kept out of the code to keep it lean.
Good to know, thanks Justin!
–1 vote

Yes.

Create a button in the Buttons & Forms Panel and choose Go to Destination as the Action.

Choose your bookmark from the Destination dropdown.

by (197k points)
No, my custom menu made by js script, not by buttons.
Ok. That wasn't clear from the question. I'll add another answer.