javascriptpushstatepdf.js

Does PDF.js raise an event as I browse between pages?


Does PDF.js raise an event as I browse between pages?

Basically I want to update the URL and add to pushstate when I browse between pages in a PDF.js document.

Does PDF.js raise an event as I browse between pages, and if so what is the event called?

Thanks


Solution

  • Yeah, there is an event named pagechange.

    You can use it like that:

    document.addEventListener('pagechange', function(e) {
      if (e.pageNumber !== e.previousPageNumber) {
        console.log('page changed from ' + e.previousPageNumber + ' to ' + e.pageNumber);
      }
    });
    

    Open the viewer and drop the code above into the console, and see what happens!