
Solid, safe website tools.
Whatever your need, Will Bontrager builds powerful software solutions.
|
(Get Attention Ticker for your web site)
Downloading and Redirecting From the Same LinkBy Will Bontrager Yesterday, I was asked if it would be easy to make a script that starts a download and then redirects the browser to a different web page. What I came up with is in two parts: An HTML <meta...> page refresh tag to do the download. And JavaScript to do the redirect. To implement, simply link to a web page of this type: The above is an entire web page that can be loaded into a browser as is. Once the above example web page is completely loaded, it waits 2 seconds then initiates a file download. This is caused by the HTML <meta...> page refresh tag in the head area of the web page. At 9 seconds after the example web page is completely loaded (7 seconds after the download kicks in), the browser window is redirected to another URL. This is caused by some JavaScript. If the page refresh URL is a 404 or causes a web page or other file to load into the browser window, rather than an automatic download to begin, then the JavaScript redirect won't happen at all. The page refresh download URL should be to an automatically downloadable file only. That would be a file with an extension like .zip or .exe. If unsure. test. Don't specify files with extension .pdf some browsers automatically download .pdf files, but others load the PDF document into the current browser window. The example web page contains some instructions. Note that the download might or might not be finished by the time the redirect occurs. If not, the download continues even thought the browser window loads a page at a different URL. The URLs and timing can be changed. See the notes in the example web page. The download must be initiated before the web page is redirected. The redirection should occur one or more seconds after the download is initiated. If the redirect happens before the download is initiated, the download won't happen. November 16, 2005 Please note: Articles on this website are presented "as is". However - If you have a question about a CGI script, HTML, CSS, PHP, or JavaScript
Rate this blog post.
No page reload! |
|
|
© 1998-2001 William and Mari Bontrager |
|