Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How to have email form send email and start file download

Reply
Thread Tools

How to have email form send email and start file download

 
 
bmurphy@xlrotor.com
Guest
Posts: n/a
 
      04-29-2006
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

 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      04-30-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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"
 
Reply With Quote
 
 
 
 
Bart Van der Donck
Guest
Posts: n/a
 
      05-01-2006
(E-Mail Removed) 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

 
Reply With Quote
 
bmurphy@xlrotor.com
Guest
Posts: n/a
 
      05-04-2006
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

 
Reply With Quote
 
Bart Van der Donck
Guest
Posts: n/a
 
      05-04-2006
(E-Mail Removed) 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

 
Reply With Quote
 
bmurphy@xlrotor.com
Guest
Posts: n/a
 
      05-05-2006
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

 
Reply With Quote
 
Bart Van der Donck
Guest
Posts: n/a
 
      05-05-2006
(E-Mail Removed) 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

 
Reply With Quote
 
bmurphy@xlrotor.com
Guest
Posts: n/a
 
      05-08-2006
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

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      05-09-2006
(E-Mail Removed) 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
 
Reply With Quote
 
bmurphy@xlrotor.com
Guest
Posts: n/a
 
      05-12-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
New to .NET ASP, need to start a project using .NET ASP, do I have to buy any Software to install, how can I start? santa19992000@yahoo.com ASP .Net 3 06-02-2007 07:03 PM
submit form, validate form, set cookie, send email, download file mhawkins19@adelphia.net Javascript 1 03-17-2005 08:19 AM
Re: How can I display a download link in my (C#) ASP.NET web form to download a file stored in my sql db? Steve C. Orr [MVP, MCSD] ASP .Net 0 03-07-2005 07:14 PM



Advertisments