Search results

Download document on window refresh or closing

02 Feb 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.
        viewer.download();
        }
    }

View sample in GitHub