Download document on window closing in EJ2 JavaScript Pdfviewer control

8 May 20231 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.

//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