javascriptcoldfusioncfdocument

Can I display a popup over a CFDOCUMENT page?


Here's what I'd like to do in Coldfusion:

On a webpage there is a "Download" href link and I want another browser tab to open when the user clicks this link. In the new tab, I am creating a PDF via CFDOCUMENT in Coldfusion. This in of itself works.

However, since the PDF has a delay before it loads in the tab, I want to display a popup to the user that the PDF may take a few moments to load.

So what I tried to do was this sequence:

User clicks "Download" -> 
On the same page, I trapped the link with jquery and displayed a popup 
window alerting the user there may be a delay ->
User clicks OK on the popup ->
Using javascript window.open, redirected to a new browser window for the PDF.

This was unsuccessful because using window.open in javascript is not trusted by browsers and the new tab doesn't show up because of popup blockers.

So then I thought I'd create a popup in the new browser tab instead before the PDF loads, but discovered I can't use javascript on a page with CFDOCUMENT.

Any ideas as to how to best accomplish this if anything can be done?


Solution

  • I think iframe might be your friend here. It allows you to display another document in the pdf page.

    Using your example in the comment, I created two files: one to display the prompt message and one to display the PDF.


    cfprompt.cfm

    <body>
    <div> this is a test </div>
    </body>
    <cfflush> 
    <iframe src="pdf.cfm" >
    </iframe>
    

    pdf.cfm

    <cfdocument format="pdf">
        <h1>Hello ColdFusion</h1>
        <p>This is <strong>PDF</strong> example document.</p>
        <p>Genereated at: <cfoutput>#TimeFormat(Now())# on #DateFormat(Now())#</cfoutput></p>
    </cfdocument>
    

    You're still going to have to play with the formatting/sizing of the iframe so that it displays correctly, but hopefully this allows you to display the PDF.