Skip to main content
New Participant
November 16, 2021
Question

Get the Bookmark Object of a Clicked Bookmark by Javascript

  • November 16, 2021
  • 2 replies
  • 1146 views
I want to make bookmarks as bellow using Javascript.
- Each bookmark has a same name as each layers in pdf.
- Each bookmark has the following action.
  When the bookmark is clicked, the only layer with same name as the bookmark will be displayed.
----------------------------------------------
var layers = this.getOCGs();
for (var j in layers){
    this.bookmarkRoot.createChild(layers[j].name, "xxxxxx");
}

----------------------------------------------

 

I want to enter the following script into "xxxxxx". (cExpr augument of createChild method)
----------------------------------------------
var layers = this.getOCGs();
for (var i in layers){
    if (layers[i].name === bookmark.name){
        layers[i].state = true;
     }
    else{
        layers[i].state = false;
    }
}
----------------------------------------------
This script expression is evaluated when the bookmark is clicked
But I can't find how to get the bookmark Object that is being clicked now...
Please give me an advice.
This topic has been closed for replies.

2 replies

try67
Community Expert
November 16, 2021

You should use a function and pass to it the name of the bookmark that triggers each event as a parameter. Since that name is also the name of the layer you could use that to identify the layer and then show it.

joyanceAuthor
New Participant
November 17, 2021

Thank you for your advice.

Brainiac
November 16, 2021

You cannot find the bookmark object last clicked. You'd need to create separate JavaScript for each bookmark, including the name. 

joyanceAuthor
New Participant
November 17, 2021

Your answer was clear and a great help for me.

I resolved it by making another script that generates separate script for each bookmark with each bookmark name.

Thank you!