madasczik
asked on
Force PDF Download is OK, Popup Remains Open on Win2k?
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(wind ow.open('# request.st r_common_d irectory#a ct_downloa d_pdf.cfm? str_filena me=#reques t.sct_pdf[ "str_file_ name#int#" ]#','downl oad','widt h=100,heig ht=100,lef t=5000,top =5000,loca tion=no,me nubar=no,s tatus=no,t oolbar=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_filena me#">
<CFHEADER NAME="content-disposition" VALUE="attachment; filename=#variables.str_fi lename#">
<CFCONTENT TYPE="application/pdf" FILE="#variables.str_fullp ath#" 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.
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(wind
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#
<CFSET variables.str_filename = "#request.str_filename#">
<CFSET variables.str_fullpath = "#variables.str_filepath##
<CFHEADER NAME="content-disposition"
<CFCONTENT TYPE="application/pdf" FILE="#variables.str_fullp
</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.
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
<body onLoad="window.close()'>
HTH
Steven
<script>
newWin = window.open('#request.str_ common_dir ectory#act _download_ pdf.cfm?st r_filename =#request. sct_pdf["s tr_file_na me#int#"]# ','downloa d','width= 100,height =100,left= 5000,top=5 000,locati on=no,menu bar=no,sta tus=no,too lbar=no, scrollbars=no, resizable=no');
</script>
<a href="javascript:newWin.cl ose();">Cl ose</a>
newWin = window.open('#request.str_
</script>
<a href="javascript:newWin.cl
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_filena me#">
<CFHEADER NAME="content-disposition" VALUE="attachment; filename=#variables.str_fi lename#">
<CFCONTENT TYPE="application/pdf" FILE="#variables.str_fullp ath#" DELETEFILE="no" RESET="no">
</CFOUTPUT>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
window.close();
//-->
</SCRIPT>
that shld do it
K'Rgds
Anand
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#
<CFSET variables.str_filename = "#request.str_filename#">
<CFSET variables.str_fullpath = "#variables.str_filepath##
<CFHEADER NAME="content-disposition"
<CFCONTENT TYPE="application/pdf" FILE="#variables.str_fullp
</CFOUTPUT>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
window.close();
//-->
</SCRIPT>
that shld do it
K'Rgds
Anand
good example AnandKP.
liked it!
---Pinal
liked it!
---Pinal
ASKER
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_di rectory#ac t_download _pdf.cfm?s tr_filenam e=#request .sct_pdf[" str_file_n ame#int#"# ', '#int#', 'width=100,height=100,left =5000,top= 5000,locat ion=0,menu bar=0,stat us=0,toolb ar=0,scrol lbars=0,re sizable=0' );">Downlo ad</a></di v>
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?
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
t = setTimeout("childWin.close
//-->
</SCRIPT>
Then the link is:
<div class="small"><a href="JavaScript:void windowOpener('#request.str
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?
Is the popup window only for prompting this file for download? Is there any other purpose for the popup window?
ASKER
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.
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=#U RLEncodedF ormat("tes t.pdf")#"> Test Text File</a>
</cfoutput>
<cfif IsDefined("URL.FileName") AND FileExists(ExpandPath('.\'
<CFHEADER NAME="content-disposition"
<CFCONTENT TYPE="application/pdf" FILE="#ExpandPath('.\') & "#URL.FileName#"#" DELETEFILE="no" RESET="no">
</cfif>
<cfoutput>
<a href="test.cfm?FileName=#U
</cfoutput>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
refer: https://www.experts-exchange.com/questions/20605536/Automatic-downloading.html
incase u have issues ...
incase u have issues ...
ASKER
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.
Glad to help u sort it out ...
Cheers :)
Anand
Cheers :)
Anand
-- Ian