JsPDF - Not allowed to navigate top frame to data URL

后端 未结 14 2226
Happy的楠姐
Happy的楠姐 2020-11-27 02:53

After updating Google Chrome, the report jsPDF in a new Window does not work any more.

The console shows the message:

Not allowed to navigate

14条回答
  •  野性不改
    2020-11-27 03:42

    /**
     * Creates an anchor element `` with
     * the base64 pdf source and a filename with the
     * HTML5 `download` attribute then clicks on it.
     * @param  {string} pdf 
     * @return {void}     
     */
    function downloadPDF(pdf) {
        const linkSource = `data:application/pdf;base64,${pdf}`;
        const downloadLink = document.createElement("a");
        const fileName = "vct_illustration.pdf";
    
        downloadLink.href = linkSource;
        downloadLink.download = fileName;
        downloadLink.click();
    }
    

    Source from: https://medium.com/octopus-labs-london/downloading-a-base-64-pdf-from-an-api-request-in-javascript-6b4c603515eb

提交回复
热议问题