By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,369 Members | 1,188 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,369 IT Pros & Developers. It's quick & easy.

How to have email form send email and start file download

P: n/a
Last week after much searching, I found the answer to my problem in
this newsgroup. I can't find the thread from which I got my solution,
but I wanted to report back what worked.

When the site visitor fills out the form and submits it, this calls a
rather ordinary asp script like formmail.asp that sends the emails and
displays a "thank you" web page. At the very end of my "thank you" web
page I placed the following:

<script type="text/javascript">
location.href="FileToDownload.exe"
</script>

This causes the file download to get triggered, and asks the user if
they want to save the file. In limited testing this appears to work
fine in both Firefox and IE.

Cheers,

Brian Murphy
Austin, Texas

Apr 29 '06 #1
Share this Question
Share on Google+
13 Replies


P: n/a
bm*****@xlrotor.com wrote:
[...]
When the site visitor fills out the form and submits it, this calls a
rather ordinary asp script like formmail.asp that sends the emails and
displays a "thank you" web page. At the very end of my "thank you" web
page I placed the following:

<script type="text/javascript">
location.href="FileToDownload.exe"
</script>

This causes the file download to get triggered, and asks the user if
they want to save the file. In limited testing this appears to work
fine in both Firefox and IE.


If, and only if, the required client-side script and DOM support
is present. You are much better off doing this server-side. At
least provide a server-side fallback.
PointedEars
--
What one man can invent another can discover.
-- Sherlock Holmes in Sir Arthur Conan Doyle's
"The Adventure of the Dancing Men"
Apr 30 '06 #2

P: n/a
bm*****@xlrotor.com wrote:
Last week after much searching, I found the answer to my problem in
this newsgroup. I can't find the thread from which I got my solution,
but I wanted to report back what worked.

When the site visitor fills out the form and submits it, this calls a
rather ordinary asp script like formmail.asp that sends the emails and
displays a "thank you" web page. At the very end of my "thank you" web
page I placed the following:

<script type="text/javascript">
location.href="FileToDownload.exe"
</script>


This code doesn't work well in Firefox - the file is offered for
download indeed, but the "Thank you" text doesn't display (FF 1.0.4. on
WinXP SP2).

I'ld suggest not to use too much exotic artificial constructions like
that.

Why not just use:

<p>Thank you. The form has been sent</p>
<p><a href="FileToDownload.exe">Click here to
download the .exe-file</a></p>

Or

<p>Thank you. The form has been sent.</p>
<iframe width="0" height="0" src="FileToDownload.exe"
style="visibility:hidden; display:none; width:0px; height:0px">
</iframe>

--
Bart

May 1 '06 #3

P: n/a
I'll have to confess I can't tell the difference between something that
is client-side and server-side.

For years my "thank you" page has had a "Click here if the download
doesn't start automatically" type of link. That was necessary because
the download never did start automatically.

The two things that appeal to me the most about the three lines of jave
script are 1) it worked when I tested it in FF and IE, and 2) it's only
three lines of script.

Forgive my ignorance, but what is it about this approach that makes it
seem exotic and artificial?

At the time I found what I consider a great, simple and elegant 3 line
solution, someone else was trying to help me solve this problem by
adding mountains of indecipherable (to me) script to my web page.

Brian

May 4 '06 #4

P: n/a
bm*****@xlrotor.com wrote:
I'll have to confess I can't tell the difference between something that
is client-side and server-side.

For years my "thank you" page has had a "Click here if the download
doesn't start automatically" type of link. That was necessary because
the download never did start automatically.

The two things that appeal to me the most about the three lines of jave
script are 1) it worked when I tested it in FF and IE, and 2) it's only
three lines of script.

Forgive my ignorance, but what is it about this approach that makes it
seem exotic and artificial?
Your code actually tries to _replace_ your current location with the
..exe file (and not to open it as a second file). Firefox implements
this more logically than MSIE; it offers the file for download and
doesn't display the original webpage (which is closer to a literal
'location change' than MSIE, that still displays the original HTML
content).

<p>Thank you.</p>
<script type="text/javascript">
location.href="FileToDownload.exe"
</script>

Your code doesn't do what you think it does, it only looks that way.
This must sound cryptic for someone who doesn't know the difference
between server side and client side software :-)
At the time I found what I consider a great, simple and elegant 3 line
solution, someone else was trying to help me solve this problem by
adding mountains of indecipherable (to me) script to my web page.


Avoiding complexity whenever you can is definitely a good coding
strategy. You'll do yourself (or your successor) a big favour with
that.

As in my previous post, I think your best option would be something
like this:

<p>Thank you. The form has been sent.</p>
<iframe width="0" height="0" src="FileToDownload.exe"
style="visibility:hidden; display:none; width:0px; height:0px">
</iframe>

--
Bart

May 4 '06 #5

P: n/a
Hello Bart,

Both Firefox 1.5.0.2 and IE 6.0 seem to behave the same. First I fill
out the form, click the button, my thank_you.html page is displayed,
and a moment later the Save File dialog box appears.

If you want to see this in action:

The form is at this address www.xlrotor.com/downloads.shtml
When you click the submit button, the formmail script is called, which
send two emails (one to me and one to the visitor) and then displays
http://www.xlrotor.com/thank_you3.shtml

If you view the page source for the thank_you page, go to the very end
and you'll see the three javascript lines. The script is outside the
body of the html code for the page (I think).

I encourage you to try it out, and to please let me know what happens.

Cheers,

Brian

May 5 '06 #6

P: n/a
bm*****@xlrotor.com wrote:
Both Firefox 1.5.0.2 and IE 6.0 seem to behave the same. First I fill
out the form, click the button, my thank_you.html page is displayed,
and a moment later the Save File dialog box appears.

If you want to see this in action:
The form is at this address www.xlrotor.com/downloads.shtml
I get "Page not found" error for that. The URL is probably

http://www.xlrotor.com/xlrotor/downloads.shtml
When you click the submit button, the formmail script is called, which
send two emails (one to me and one to the visitor) and then displays
http://www.xlrotor.com/thank_you3.shtml

If you view the page source for the thank_you page, go to the very end
and you'll see the three javascript lines. The script is outside the
body of the html code for the page (I think).

I encourage you to try it out, and to please let me know what happens.


Yes - that works fine here too. I ran my previous test on Firefox on
the local xp filesystem (C:\Documents and Settings\etc.), where it
appears to have a different result. But I think this emphasises my
previous point.

--
Bart

May 5 '06 #7

P: n/a
Oops. The first url should have been
http://www.xlrotor.com/xlrotor/downloads.shtml

But you probably don't need to bother with that one if you have already
followed the second one.

I've done some more digging around about automatic file downloads.
What if I place the following line in the <HEAD> section of my
"thank_you3.shtml" page.

<META HTTP-EQUIV="Refresh" CONTENT="3; URL=http://FileToDownload.exe">

A web page I visited tonight displayed a page that had a "click here if
the file download doesn't start automatically within a few seconds".
The file download did start automatically, so I did a "view source" to
try to see how it did this, and it appears to do this using a tag like
the one shown above. The value 3 is the number of seconds to wait
before showing the specified URL. They actually had 9 seconds in their
implementation, but that seems like a long time to wait

I thought I'd ask before trying it myself. It seems to be just a one
line html tag without any scripting trickery. It would be simple to
add this line to my "thank_you3.shtml" page, and remove the js code
I've got there now.

I very much appreciate your help on this.

Brian

May 8 '06 #8

P: n/a
bm*****@xlrotor.com wrote:
But you probably don't need to bother with that one if you have already
followed the second one.

I've done some more digging around about automatic file downloads.
What if I place the following line in the <HEAD> section of my
"thank_you3.shtml" page.

<META HTTP-EQUIV="Refresh" CONTENT="3; URL=http://FileToDownload.exe">
Since the URL points to a nonexisting resource (_host_ FileToDownload.exe,
implicitly assuming "/" [DocumentRoot] as request URI), it is not going to
work. The best thing that can happen then is an error message box, and the
worst thing using this as search string for $search_engine and redirecting
you to the first hit.

And no UA is required to support this element type-attribute combination
anyway; in fact, there are some where it is explicitly not supported, or
where support for it can be disabled.
A web page I visited tonight displayed a page that had a "click here if
the file download doesn't start automatically within a few seconds".
The file download did start automatically, so I did a "view source" to
try to see how it did this, and it appears to do this using a tag like
the one shown above.
I am certain that there were several differences to the above.
[...]
I thought I'd ask before trying it myself.
Since when is this a Good Thing on Usenet? Asking about the why of things
you do not fully understand is OK, but there is no excuse for not trying
before posting; unless, of course, you expected it to do something harmful
and had no test environment. Did you, really?
It seems to be just a one line html tag without any scripting trickery.
It is. Read the HTML 4.01 Specification.
It would be simple to add this line to my "thank_you3.shtml" page, and
remove the js code I've got there now.


That would not help you either, unless you provided the full URL somehow
(which is best achieved with server-side scripting, as you can see on
downloads.com, sourceforge.net aso.). It can serve as a fallback for
client-side `location=...', but you SHOULD provide the download link anyway
for the reasons given above. (Remember those "<if the download does not
start, click here>" messages?)
PointedEars
--
I hear, and I forget; I see, and I remember; I do, and I understand.
-- Chinese proverb
May 10 '06 #9

P: n/a
I realize the URL needs to be fully qualified. I mistakenly type it
shortand for the newsgroup post. Sorry about that.

Today I witnessed a friend trying out my page that has the 3 line js
script with IE6, and it didn't start the download by itself. So I have
removed the js lines and put the following html line near the front of
the file "www.xlrotor.com/thank_you3.shtml"

<META HTTP-EQUIV="Refresh" CONTENT="3;
URL=http://www.xlrotor.com/xlrotowm30.exe">

This works when tested on my computer with IE6 and Firefox.

I need to do more testing.

Anyone who wants to try it can simply follow the link above and see if
the "file save" dialog appears about 3 seconds or so after the page
appears in your browser. The file download is 23 MB, so you probably
will want to cancel out of the download.

Brian

May 12 '06 #10

P: n/a
bm*****@xlrotor.com said the following on 5/11/2006 11:56 PM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

<URL: http://www.safalra.com/special/googlegroupsreply/ >
Today I witnessed a friend trying out my page that has the 3 line js
script with IE6, and it didn't start the download by itself.
Probably has JS disabled then.

So I have removed the js lines and put the following html line near
the front of the file "www.xlrotor.com/thank_you3.shtml"

<META HTTP-EQUIV="Refresh" CONTENT="3;
URL=http://www.xlrotor.com/xlrotowm30.exe">
IE6:

Tools>Security>Custom Level

Downloads section
3 settings to ponder

Last Section, explicitly disable META Refresh
This works when tested on my computer with IE6 and Firefox.

I need to do more testing.


Yes, indeed.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 12 '06 #11

P: n/a
bm*****@xlrotor.com wrote:
<META HTTP-EQUIV="Refresh" CONTENT="3;
URL=http://www.xlrotor.com/xlrotowm30.exe">

This works when tested on my computer with IE6 and Firefox.

I need to do more testing.


Usually testing is a Good Thing, but it is the path to the Dark Side here.

You can _never_ test 100% of the cases; so you have to provide a fallback
for _unknown_ cases where a certain technique does not work due to _unknown_
reasons. You really should read (my) postings more thoroughly.
PointedEars
--
A true translation needs neither omissions nor addings.
It is its own content.
-- me, 2003
May 13 '06 #12

P: n/a
That's a dizzying collection of options that IE has.

So it certainly seems the automatic triggering of the file download is
hit or miss on any given system. So the "click here if the download
does not start automatically" is mandatory, and I do have this.

Unless I discover any as yet unseen problems, I think the single line
HTML META tag is the way to go for the file download. I will continue
to test it on other computers whenever the opportunity arises.

Thanks,

Brian
Randy Webb wrote:
bm*****@xlrotor.com said the following on 5/11/2006 11:56 PM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

<URL: http://www.safalra.com/special/googlegroupsreply/ >
Today I witnessed a friend trying out my page that has the 3 line js
script with IE6, and it didn't start the download by itself.


Probably has JS disabled then.

So I have removed the js lines and put the following html line near
the front of the file "www.xlrotor.com/thank_you3.shtml"

<META HTTP-EQUIV="Refresh" CONTENT="3;
URL=http://www.xlrotor.com/xlrotowm30.exe">


IE6:

Tools>Security>Custom Level

Downloads section
3 settings to ponder

Last Section, explicitly disable META Refresh
This works when tested on my computer with IE6 and Firefox.

I need to do more testing.


Yes, indeed.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


May 14 '06 #13

P: n/a
bm*****@xlrotor.com said the following on 5/14/2006 12:27 AM:
That's a dizzying collection of options that IE has.
Very dizzying.
So it certainly seems the automatic triggering of the file download is
hit or miss on any given system. So the "click here if the download
does not start automatically" is mandatory, and I do have this.
It's not mandatory, it's just the most reliable of the methods available.
Unless I discover any as yet unseen problems, I think the single line
HTML META tag is the way to go for the file download. I will continue
to test it on other computers whenever the opportunity arises.


Even knowing that META tags can be disabled and admitting that the link
is the way to go, why are you still using a faulty approach?
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 14 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.