javascript - Changing the page of an embeded .pdf using a link -


i can use "#page=[pagenumber]" after src ensure pdf opens respective page, don't understand how use variable in place of [pagenumber] , change variable when tab/button pressed.

what recommend looping on each of links document.getelementsbytagname('a'), , attaching click handler each of links. can target clicked link's target splitting on href this.href.split("=")[1].

in following example, i'm assigning this.href.split("=")[1] variable clicked, can reference whenever want know last link clicked.

var clicked;  var links = document.getelementsbytagname('a');  (var = 0; < links.length; i++) {    links[i].onclick = function(e) {      e.preventdefault();      clicked = this.href.split("=")[1];      console.log("you clicked link: " + clicked);    }  }
<a href="?page=1">page 1</a>  <a href="?page=2">page 2</a>  <a href="?page=3">page 3</a>

note above example uses e.preventdefault(); prevent click action going through. remove line allow clicks open relevant pages in actual code; clicked variable still updated.

hope helps! :)


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -