Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Force PDF Download is OK, Popup Remains Open on Win2k?

Posted on 2004-10-18
13
2,098 Views
Last Modified: 2013-12-24
I've successfully forced a PDF to come up with a file download box.  The popup on XP SP2 with all IE updates works perfect, it opens a 100x100 pixel box in the lower right of the screen, after you hit the save button the file downloads and the popup closes.  I see hidden popups are not allowed offscreen anymore with all the new IE updates.

On another PC with win2k, the popup box is hidden off screen, the file downloads OK, but the popup doesn't close after the file is downloaded successfully.  Attempted to use <<body onLoad="window.close();"> but it seems that using the CFHEADER AND CFCONTENT tages forces everything else to be ignored.


Here I am calling act_download_pdf.cfm with the filename attached to the URL

<a href="JavaScript:void(window.open('#request.str_common_directory#act_download_pdf.cfm?str_filename=#request.sct_pdf["str_file_name#int#"]#','download','width=100,height=100,left=5000,top=5000,location=no,menubar=no,status=no,toolbar=no, scrollbars=no, resizable=no'));">Download</a>


Then in the act_download_pdf.cfm I have the following code to force the PDF to open a Save As box

<CFOUTPUT>

<CFSET variables.str_filepath = "#request.str_server_root#documents/">
<CFSET variables.str_filename = "#request.str_filename#">
<CFSET variables.str_fullpath = "#variables.str_filepath##variables.str_filename#">

<CFHEADER NAME="content-disposition" VALUE="attachment; filename=#variables.str_filename#">
<CFCONTENT TYPE="application/pdf" FILE="#variables.str_fullpath#" DELETEFILE="no" RESET="no">

</CFOUTPUT>

Is there anyway to make sure the popup closes by itself, or is there another work around besides using Zip files?  Not sure if I should post this is a javascript forum, thought I'd ask the CF masters prior to doing so.  Thanks for any help in advance.
0
Comment
Question by:madasczik
  • 4
  • 3
  • 3
  • +3
13 Comments
 
LVL 7

Expert Comment

by:black0ps
ID: 12341030
That's a tough one. I don't know Javascript enough to know the in's and out's of popups and closing. As an alternative, you may want to consider using iFrames on the same page instead of poping up a window for the content download. If the popup window is solely for the purpose of downloading a PDF document, I would suggest using iFrames (the iFrame could be a 1px x 1px frame with code in it).

-- Ian
0
 
LVL 5

Expert Comment

by:smaglio81
ID: 12341348
I think this is the way to force a window to after popping up with javascript. Not positive though.

<body onLoad="window.close()'>

HTH

Steven
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 12343481
<script>
newWin = window.open('#request.str_common_directory#act_download_pdf.cfm?str_filename=#request.sct_pdf["str_file_name#int#"]#','download','width=100,height=100,left=5000,top=5000,location=no,menubar=no,status=no,toolbar=no, scrollbars=no, resizable=no');
</script>

<a href="javascript:newWin.close();">Close</a>
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 17

Expert Comment

by:anandkp
ID: 12344676
Hi,
after this code on act_download_pdf.cfm - just write
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
      window.close();
//-->
</SCRIPT>


eg: =======================================================================

<CFOUTPUT>

<CFSET variables.str_filepath = "#request.str_server_root#documents/">
<CFSET variables.str_filename = "#request.str_filename#">
<CFSET variables.str_fullpath = "#variables.str_filepath##variables.str_filename#">

<CFHEADER NAME="content-disposition" VALUE="attachment; filename=#variables.str_filename#">
<CFCONTENT TYPE="application/pdf" FILE="#variables.str_fullpath#" DELETEFILE="no" RESET="no">

</CFOUTPUT>

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
      window.close();
//-->
</SCRIPT>

that shld do it

K'Rgds
Anand
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 12344829
good example AnandKP.
liked it!
---Pinal
0
 

Author Comment

by:madasczik
ID: 12349047
anandkp - that still doesn't work for me, seems that when CFHEADER and CFCONTENT are used, it ignores all other code in that file. So far the only way I've found to get it to close is to put a timer on the popup prior to it opening.

I left the act_download_pdf.cfm as is for now.

Then changed the popup script to this:

<SCRIPT language="javascript">
   <!--
   function windowOpener(url, name, args)
   {
   childWin = window.open(url,name,args);
   }
   var t;
   t = setTimeout("childWin.close()",10000);
   t = setTimeout("childWin.close()",20000);
//-->
</SCRIPT>

Then the link is:

<div class="small"><a href="JavaScript:void windowOpener('#request.str_common_directory#act_download_pdf.cfm?str_filename=#request.sct_pdf["str_file_name#int#"#', '#int#', 'width=100,height=100,left=5000,top=5000,location=0,menubar=0,status=0,toolbar=0,scrollbars=0,resizable=0');">Download</a></div>

With it this way, the window will try to close after 10 and 20 seconds.  Only problem with this is that the timer is pretty chessy, if you click on multiple downloads, the timer starts over and the previous box will not close.

Any know how to setup a coldfusion timer in session so each download box will have a unique timer that keeps trying to close the window no matter how long it takes to download?
0
 
LVL 7

Expert Comment

by:black0ps
ID: 12349186
Is the popup window only for prompting this file for download? Is there any other purpose for the popup window?
0
 

Author Comment

by:madasczik
ID: 12349283
blackOps - yeah im passing the file name to the act_download_pdf.cfm. I tried it both ways with just a new blank window and a popup, same results occur on win2000, the new window/popup doesn't close after the file finishes downloading.  If there's a way to invoke the download dialog box without a new window, that would be better.
0
 
LVL 7

Expert Comment

by:black0ps
ID: 12350282
How bout this? To test this, save a file called test.pdf on your c:\ drive. You will replace those paths and file names in your application though.

<cfif IsDefined("URL.FileName") AND FileExists(ExpandPath('.\') & "#URL.FileName#")>
<CFHEADER NAME="content-disposition" VALUE="attachment; filename=#ExpandPath('.\') & "#URL.FileName#"#">
<CFCONTENT TYPE="application/pdf" FILE="#ExpandPath('.\') & "#URL.FileName#"#" DELETEFILE="no" RESET="no">
</cfif>

<cfoutput>
<a href="test.cfm?FileName=#URLEncodedFormat("test.pdf")#">Test Text File</a>
</cfoutput>
0
 
LVL 17

Accepted Solution

by:
anandkp earned 500 total points
ID: 12356065
ok madasczik ... yes ur right - sorry abt that ... i didnt realise ...

give a direct link & tell me what u get

<a href="#request.str_common_directory#act_download_pdf.cfm?str_filename=#request.sct_pdf["str_file_name#int#"]#">Download</a>
0
 
LVL 17

Expert Comment

by:anandkp
ID: 12356087
0
 

Author Comment

by:madasczik
ID: 12360324
anandkp - funny enough, I based my code off the link you provided. I guess it all started going wrong when i first used a target="_blank" on the link then thought too much into it from there.  I got rid of popup all together and used the standard link like you said.  Thanks.
0
 
LVL 17

Expert Comment

by:anandkp
ID: 12360343
Glad to help u sort it out ...

Cheers :)
Anand
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Citrix netscaler connection to Web Interface 9 126
Htaccess - if subdomain "dev." 2 80
question about access to website 2 79
How to stress test an ASP.NET https website 3 78
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question