4 Replies Latest reply on Nov 16, 2015 7:35 AM by LyndonPatton

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

    LyndonPatton Level 1

      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>

        • 1. Re: Javascript will not execute if a cfdocument tag is in a document
          Jamo Level 2

          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.

          • 2. Re: Javascript will not execute if a cfdocument tag is in a document
            LyndonPatton Level 1

            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.

            • 3. Re: Javascript will not execute if a cfdocument tag is in a document
              LyndonPatton Level 1

              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?

              • 4. Re: Javascript will not execute if a cfdocument tag is in a document
                LyndonPatton Level 1

                Happiness!

                 

                Jamo, you the man! An <Iframe> tag did it.

                 

                Thank you so much.

                 

                Passing the BadgeID as a url variable did not work, but a session var worked fine.

                [code]

                <cfoutput>

                    <script>

                        window.opener.document.getElementById('photoTitle').innerHTML='#BadgeID#';

                    </script>

                </cfoutput>

                <cfset Session.BadgeID=#BadgeID#>

                <cfswitch expression="#Form.CardFormat#">

                    <cfcase value="White">

                        <iframe src="WhiteOccupationalLicense.cfm"></iframe>

                    </cfcase>

                [/code]