Reputation: 23565
In answers to other questions it was pointed out that SourceForge's download page worked by adding a hidden <iframe>. This does no longer seem to be the case...
How is the current version of the download page implemented? I'd like to build something similar because I consider SF's solution quite elegant.
Ok, more precisely...True, the initial "question" was too vague.
If you go to http://sourceforge.net/projects/beankeeper/files/beankeeper/2.6.2/beankeeper-2.6.2.tar.gz/download there's a plain old HTML link to download the file in question but there's also an automatic download. The delay seems to be some 2s.
Someone asked for my particular use case. I'll answer that knowing that it might divert from the OP to a certain extent. Very much simplified:
If I adopted SF's model a form submit would trigger the dispatcher Servlet and reload the current page (regular behavior). Upon reload of the page I would somehow - right, how does SF do that? - cause the browser to invoke the document Servlet.
Upvotes: 3
Views: 2503
Reputation: 1109725
Just change the window location during page load.
Here's an SSCCE, just copy'n'paste'n'run it.
<!doctype html>
<html lang="en">
<head>
<title>SO question 2222034</title>
<script>
window.onload = function() {
setTimeout(function() {
window.location = 'http://download.java.net/maven/1/jstl/jars/jstl-1.2.jar';
}, 2000); // It's "cool" to let user wait 2 more seconds :/
}
</script>
</head>
<body>
<p>The download of jstl-1.2.jar will start shortly...</p>
</body>
</html>
Or if you need to use POST, just submit a hidden form:
<!doctype html>
<html lang="en">
<head>
<title>SO question 2222034</title>
<script>
window.onload = function() {
setTimeout(function() {
document.getElementById('downloadform').submit()
}, 2000); // It's "cool" to let user wait 2 more seconds :/
}
</script>
</head>
<body>
<p>The download of jstl-1.2.jar will start shortly...</p>
<form id="downloadform" action="http://download.java.net/maven/1/jstl/jars/jstl-1.2.jar"></form>
</body>
</html>
Upvotes: 8
Reputation: 115877
This is strictly MHO, but I personally do not find neither SourceForge's, nor CodePlex's download pages particularly elegant. Take a look at Google Code: clicking a hyperlink initiates download immediately, without asking you to accept a license agreement of any kind, select download mirror or view dozens of banners. It just does what it has to do: allow users to download whatever file they're interested in.
Upvotes: 5