1

I am calling below jquery method to export the table details into PDF. PDF file is created in the java class while it is called and available in the path C:\apache-tomcat-7.0.40\webapps\TestProj\PDFfiles and the JSP where im having this script is loacted at C:\apache-tomcat-7.0.40\webapps\TestProj\WEB-INF\jsp But window.open is not working. I can get the alert message of "PDF generation success ---"

Any idea? Please help.

function openPDF() {
        $.post("generatePDF", {action : "get"}, function(data) {
            if (data.returnStatus == "SUCCESS") {               
                alert("PDF generation success ---");
                var win = window.open('', 'fullscreen=no');
                win.location.href = '../../PDFfiles/TestPdf.pdf';
                win.focus(); 
                //window.open('../../PDFfiles/TestPdf.pdf', 'fullscreen=no');

            }
        }, 'json');     
    }

I have tried below snippet also but no use..

window.open('../../PDFfiles/ShopsListPdf.pdf', 'fullscreen=no');
JPN
  • 683
  • 3
  • 11
  • 24

1 Answers1

2

window.open works only on user actions like click but if there is a delay after that it will be blocked by browser. delay like you have made in ajax call. So try to execute window.open asap after click

Note: sometimes when ajax call come too fast due to cache or something, the window.open may work, it happens to me lot of time, specially when I was trying to make a facebook login here the link when I posted a question fb login popup block

Community
  • 1
  • 1
Rohit Agrawal
  • 5,372
  • 5
  • 19
  • 30
  • when I call generatePDF, that class actually generates the PDF from the data from session and place the PDF in C:\apache-tomcat-7.0.40\webapps\TestProj\PDFfiles So it is like I need to open a pdf file from the folder. – JPN May 29 '13 at 18:58
  • then you can just make a button to `generate a pdf` and when done change the button text to `download it` and 2nd click on that can be use as window.open – Rohit Agrawal May 29 '13 at 18:59
  • or you can do that open a window with a page which have a code to generate the pdf on page load event and display – Rohit Agrawal May 29 '13 at 19:01