Skip to main content
Inspiring
November 12, 2015
Answered

Javascript will not execute if a cfdocument tag is in a document

  • November 12, 2015
  • 1 reply
  • 1423 views

I have a popup form action page that opens by using the form/target="_blank"  attribute.

The new document does a database insert and then creates a PDF using the <cfdocument> tag.

I'm trying update some elements on the parent/opener form page as it is common for the client to continue using the parent, make some changes, and generate another PDF. If I comment out the <cfdocument> tag my code works fine, the parent document is updated as I expected.

I'm not sure how to proceed, help much appreciated!

thanks, Lyndon

Javascript I'm trying to run just before the <cfdocument> tag:

<script>

        window.opener.document.getElementById('photoListTitle').innerHTML='test update';

</script>

Tag Attributes:

<cfdocument

        localUrl="yes"

        format="PDF"

        pageType="custom"

        pageWidth="2.2"

        pageHeight="3.375"

        marginBottom="0"

        marginTop="0"

        marginLeft="0"

        marginRight="0"

        orientation="portrait"

        backgroundVisible="yes"

        fontEmbed ="true"

        filename="PDFs/#Replace(BadgPhotoName,'.jpg','.pdf','All')#"

        overwrite="true">

          html...

</cfdocument>

    This topic has been closed for replies.
    Correct answer James Moberg

    What happens after the PDF is generated?  Is it automatically downloaded to the browser?  Have you tried using a hidden iFrame and some sort of modal notification to display that the file is being generated?  You could have the iframe page trigger a parent function to update HTML and return the link to the PDF file (so that it isn't automatically downloaded).  Files that are automatically downloaded performs a reset and any anything before the file download is ignored.

    1 reply

    James Moberg
    James MobergCorrect answer
    Inspiring
    November 13, 2015

    What happens after the PDF is generated?  Is it automatically downloaded to the browser?  Have you tried using a hidden iFrame and some sort of modal notification to display that the file is being generated?  You could have the iframe page trigger a parent function to update HTML and return the link to the PDF file (so that it isn't automatically downloaded).  Files that are automatically downloaded performs a reset and any anything before the file download is ignored.

    Inspiring
    November 13, 2015

    The PDF is the action page from my form. Adobe Reader (or the clients PDF reader) is the opener as the <cfdocument> tag make the server send the client a PDF file.

    It seems once the template with a <cfdocument> tag opens, there is no DOM reference to the opener, since it's not an html file (that's my guess at this point anyhow).

    I've decided I need to work on a solution that uses <cflocation> to get the client to the <cfdocument> tag instead of the <cfinclude> tag I'm using now. That way, hopefully, I can use the form/target CFML template to  insert my database record, update the parent page, and pass the new record ID as a url variable to a third template that contains my <cfdocument> tag. Then I can query the new record to get the information the <cfdocument> needs to do the print job.

    I'll report back.

    Inspiring
    November 16, 2015

    Well.... Disappointment.

    <cflocation> has the same behavior???  If I comment out the cflocation tag the parent page updates, execute it and it does not.

    I thought for sure it would work since I'm opening a new template.

    Any ideas?