PDA

View Full Version : force-download pdf with iframe/location/ux.report problems in IE



Aero
6 Jan 2011, 8:02 PM
Hi,

I am running out of ideas on how to force-download a pdf file when the user click the appropriate ext button. I dont know if this is a client/Ext related question at all bu i dont think my server-side script headers are wrong or anything like that. They work in FF,chrome etc.

Basically,upon click a pdf is generated on the fly within a managedIframe and then a simple meta-redirects to a force download script. This leads IE to pick up a download alert (yellow stausbar) but upon allow this file to download IE refreshes the page (which leads us to welcome page of my EXT-application) and totally forget to actually download the file and the entire Content Disposition header)

I have tried using Condors ux.report component,it works on the welcome page (myapplication.php where the application resides), but not when you have a grouptabpanel with items (which have extended classes ) and you want to download being in one of these tabs.Somehow it seems that it also gets a new header. There are sessions involved in my app,but i find it strange anyway.

What to do ??

Prompt the user to download "something" on the welcome/start page and thus accept the site as trustwhorty then user can force-download from anywhere on the domain (even within the tabs) ?

Any ideas ?

I have tried every possible solutions with managedIframes and re-directs but the main problem seems to be the IE-refresh mechanism.This reload mechanism seems to be in conflict with how we want to work with javascript and AJAX.

Condor
7 Jan 2011, 3:24 AM
I don't understand your second paragraph. How exactly are you downloading the pdf?

Aero
7 Jan 2011, 4:38 AM
Hi Condor,

Kinda hard to explain,mabey i can put some screenshots up.

When a user logs in he arrives to application.php with a grouptabpanel.js. If i place your ux.report component in this js file i can download the file. Just like this:





var report = new Ext.ux.Report({
renderTo: Ext.getBody()
});
report.load({
url: absolute-path/forcepdf.php?file=file.pdf'

});



Where forcepdf.php have an the needed headers for the content attachment Disposition.

I haven't done any buttons to call this code just put it directly after Ext.onReady.

However in the grouptabpanel i have four items all being extensions of formpanel (with a included grid and toolbar).
On the toolbar i have a button (save) which i would like to do exactly what the ux.report does,but if i place the report component within the button handler i get the effect of IE picking it up just to reload the page and then forgets to actually download it(promt the user with a Save-As dialog box).

Open up yet a new Ext-window with an embedded iframe or html doesn't help,same mechanims takes place.Seems i really need to upon up a new pop-up window (window.open effects).

So,what i would like to do upon (save) click is to call a ext-window(item iframepanel) with a src to the script that genrates and put the file onto the server.Then on documentloaded or any callback i simply put the uxreport and the user is prompted with save-as dialog.

If, i place the ux.report component like i did in the beginning and download the file IE thinks "hey this site is ok to download from" and i never get the download warning message more in this session so then it works to download from the within the grouptabpanel items. But why promt the user to download "something" just so he can use it for later on.

Any help ?

Thanks

Condor
7 Jan 2011, 4:48 AM
When you want to execute this on a button click then I recommend using Animal's LinkButton instead. It has the advantage of allowing mouse right-click Save As too.

Another option would be submitting a hidden form to target="_blank", but existing Ext code isn't really suited for that. You would have to make a rip-off of Ext.data.Connection.doFormUpload.

Aero
7 Jan 2011, 6:14 AM
Thank you Condor,

I will look into Animals linkButton.But the handler of my save button controls some other business logic as well before actually being able to href any file so i am not sure i can make use of it for this appliation.

Instead i can probably use this button or html a href with target _blank (thanks for the hint on this one!) in a ext-window that pops up upon clicking Save. Yes,it means a extra click for IE users to actually get the file but atleast it doesnt reload the application itself.

So for instance after some business logic on the save button i just launch yet a new window saying "please click this link to get your report":



documentloaded :function() {

if(Ext.isIE){

var win = new Ext.Window ({
height: 400,
width: 400,
title: 'Report finished',
html: '<a href=\"#\" onClick=javascript:window.open(....)</a>'
});
}