Search results

Download document on window refresh in JavaScript (ES5) PDF Viewer control

08 May 2023 / 1 minute to read

The PDF Viewer library allows you to download a PDF document rendered in the viewer while refreshing the window or clicking the close window using the onbeforeunload event.

Step 1: Follow the steps provided in the link to create a simple PDF Viewer sample.

Step 2: Add the following code sample to download a PDF document while refreshing or closing the window.

Copied to clipboard
//The event triggers while closing or refreshing the window.
window.onbeforeunload = function(e){
        var message = "Do you want to close the page?"
        e = e || window.event;
        //For IE and Firefox.
        if (e) {
        e.returnValue = message;
        //Method to download the document.;

View sample in GitHub