Reputation:
I have this lead generation form and after they give us their information, I would like the form's thank you page to popup a window where the user can save the file or open it.
This web page will be served from a Microsoft server so .net C# or javascript are options.
thx
Upvotes: 1
Views: 1135
Reputation: 6308
Good luck getting any browser to open an .exe file... Warning Will Robinson... Warning...
Anyways, here's a snippet....
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + downloadName);
while (dataToRead > 0)
{
if (Response.IsClientConnected)
{
fileLength = iStream.Read(buffer, 0, buffer.Length);
Response.OutputStream.Write(buffer, 0, fileLength);
Response.Flush();
dataToRead = dataToRead - fileLength;
}
else
{
dataToRead = -1;//prevent infinite loop if user disconnects
}
}
Edit: Ok, i suppose you could create the thank you page with a hidden button on it, inject some javascript to click that button upon load, which would then execute the code to dump the file into the response stream.
Upvotes: 2
Reputation: 13266
I Assume, your problem is to display a thank you page, and also to open a new save / run dialog.
The below js code, / HTML code in the thank you page will render the thank you page, and make the browser request for the file mentioned in the URL. If that is configured properly as mentioned by others, it will prompt the dialog
Try
Javascript
document.write("<META HTTP-EQUIV=\"refresh\" content=\".1; URL=http://domain.come/my.exe\">");
HTML
<META HTTP-EQUIV="refresh" content=".1; URL=http://domain.come/my.exe">
Upvotes: 2
Reputation: 1594
You cannot launch a file on the users machine unless you have some ActiveX control or Java applet with permissions to do so installed.
You can create the file on your server and send it to the browser. The user will be prompted to save or open the file.
Upvotes: 0
Reputation: 105878
I would imagine your answer could be find in one of these previous questions
https://stackoverflow.com/search?q=force+download
Upvotes: 0