/    Sign up×
Community /Pin to ProfileBookmark

ways do initiate a download

So I have a report php page where a user fills out a form, selects a bunch of options, the last one is a jquery select box which chooses what kind of file the report will be downloaded as. These reference java classes on a tomcat server that generate the file and return it when called by its url.

Soo.. What i’m trying to do is once the final option is selected and they press the go button, do all the prework and initiate the download. However I’m running into problems with ways to make this work right.

I can’t use the conventional headers for content and readfile, as i’ve already sent headers previously in the script/page. I created a download.php to hide the url and send headers off a clean script.

I need to somehow download or open in a new window: “http://site/download.php?file=pdfreport

I’ve tried using every javascript and jquery method i can think of. If it tries to open a new window or new tab, Firefox and IE both “block pop up” warning comes up – and that’s not really acceptable for a business app, imo.

Tried using an <a href> link and using javascript to .click() it, however that still triggers the firefox and IE stock pop-up blockers.

I’ve tried using <object> but never got it to actually download/hit that page.

Tried using hidden <iframe> tags and just specifing the src= as the url i want to download, and it works, however whenever the iframe is shown on the page (after submission), all other javascript on the pages stop working. IE my JS menu, calendars, collapsable panels. It’s like it loads this iframe which starts a download/pop-up, and it stops loading all the javascript on the page or something.. I don’t really know. I haven’t found a good way to refresh the page either afterwards (which might resolve it), because refreshing the page without accepting or finishing the download cancels it.

IDK, i hope that makes sense. I’m looking for ideas of other ways I can initiate a download of a url, without breaking the JS on the page or without getting a pop-up block warning in IE or FF.

Thanks everyone!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@therootauthorJun 03.2012 — I might've found a way right after posting this thread, lol.

I have to test more to verify, and I guess still am open to input, but so far this seems to be working:

[CODE]
<meta http-equiv="REFRESH" content="0;url=/download.php?file=pdfreportf&name=DepartmentStatistics.pdf">
[/CODE]


That opens that page/starts the download of the file, without killing the JS on the current page, or making the page divs go off, and doesnt cause any pop up warnings since it's "opening/refreshing" in the same tab.

Thanks
Copy linkTweet thisAlerts:
@VBAssassinJun 03.2012 — You can force a download using a content-disposition http header via PHP. Maybe use that download.php file in conjunction with AJAX?
Copy linkTweet thisAlerts:
@therootauthorJun 03.2012 — You can force a download using a content-disposition http header via PHP. Maybe use that download.php file in conjunction with AJAX?[/QUOTE]

Yeah I've already sent headers in the main page so i couldn't do it that way. download.php is actually using content-disposition and readfile to download it properly, but i just needed a way to "redirect" or open that page. I tried several ajax/jquery/js methods, and they all had the same results : if they opened in current tab, once it opened that page (which didnt take you to another page just initiated a download/dialog) - it stops loading all other js/jquery on the main page. if it's opened in a new tab/window, you get a pop-up warning from firefox or IE saying it's blocked this page from opening a new one, blah blah.

I threw that <meta> tag in the body (php script determines when/if it needs to be called), and it worked lol. Probably not the best solution since meta tags are supposed to only be in the head, but for some reason its working on all browsers.
Copy linkTweet thisAlerts:
@VBAssassinJun 03.2012 — To be honest wit you, i'm still not really sure what the heck it is you're trying to do :/ but at least you have sorted it now ?
×

Success!

Help @theroot spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...