473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Download & Javascript

Hi,

Following problem, and I can't find any solution for that:

I have an aspx page, which will (finally) generate an XLS-File which must
(can) be downloaded from the user. After that, the window should close
automatically.

Well, the first part for itself is easy with Response.WriteFile().....
The second one for itself is also easy with JS window.close()

Well, combining them seems to be much complicated. The file will be
downladed, but there's no "auto-close" effect.

Any suggestions ?
WBR,
Marc

<snip>
string script = "<script language='javascript'>window.close()</script>";
Response.ClearContent();
Response.ClearHeaders();
Response.Clear();
Response.ContentType = "application/zip;filename=download.zip";
Response.AppendHeader("Content-Disposition",
"attachment;filename=download.zip");
Response.AppendHeader("Content-Length", fi.Length.ToString());
Response.WriteFile(zipFile, 0, fi.Length);
Response.Write(script);
if(!IsStartupScriptRegistered("closepopup"))
this.RegisterStartupScript("closepopup", script);
Response.Flush();
</snap>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 19 '05 #1
6 1853
Response.Write("window.close();");

Eliyahu

"Marc Ris" <ma*******************@ris-web.net> wrote in message
news:42**********@127.0.0.1...
Hi,

Following problem, and I can't find any solution for that:

I have an aspx page, which will (finally) generate an XLS-File which must
(can) be downloaded from the user. After that, the window should close
automatically.

Well, the first part for itself is easy with Response.WriteFile().....
The second one for itself is also easy with JS window.close()

Well, combining them seems to be much complicated. The file will be
downladed, but there's no "auto-close" effect.

Any suggestions ?
WBR,
Marc

<snip>
string script = "<script language='javascript'>window.close()</script>";
Response.ClearContent();
Response.ClearHeaders();
Response.Clear();
Response.ContentType = "application/zip;filename=download.zip";
Response.AppendHeader("Content-Disposition",
"attachment;filename=download.zip");
Response.AppendHeader("Content-Length", fi.Length.ToString());
Response.WriteFile(zipFile, 0, fi.Length);
Response.Write(script);
if(!IsStartupScriptRegistered("closepopup"))
this.RegisterStartupScript("closepopup", script);
Response.Flush();
</snap>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption

=----
Nov 19 '05 #2
Eliyahu,
Thanks for your reply.

Unfortunately, the window remains open. No effect at all. (I already tried
this earlier, and tried again now...)

WBR,
Marc
Response.Write("window.close();");

Eliyahu

"Marc Ris" <ma*******************@ris-web.net> wrote in message
news:42**********@127.0.0.1...
Hi,

Following problem, and I can't find any solution for that:

I have an aspx page, which will (finally) generate an XLS-File which must (can) be downloaded from the user. After that, the window should close
automatically.

Well, the first part for itself is easy with Response.WriteFile().....
The second one for itself is also easy with JS window.close()

Well, combining them seems to be much complicated. The file will be
downladed, but there's no "auto-close" effect.

Any suggestions ?
WBR,
Marc

<snip>
string script = "<script language='javascript'>window.close()</script>";
Response.ClearContent();
Response.ClearHeaders();
Response.Clear();
Response.ContentType = "application/zip;filename=download.zip";
Response.AppendHeader("Content-Disposition",
"attachment;filename=download.zip");
Response.AppendHeader("Content-Length", fi.Length.ToString());
Response.WriteFile(zipFile, 0, fi.Length);
Response.Write(script);
if(!IsStartupScriptRegistered("closepopup"))
this.RegisterStartupScript("closepopup", script);
Response.Flush();
</snap>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet

News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+

Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption

=----


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 19 '05 #3
Is it a popup?

Try putting

<base target=_self>

in the <head> section.

Eliyahu

"Marc" <ma*******************@ris-web.net> wrote in message
news:42**********@127.0.0.1...
Eliyahu,
Thanks for your reply.

Unfortunately, the window remains open. No effect at all. (I already tried
this earlier, and tried again now...)

WBR,
Marc
Response.Write("window.close();");

Eliyahu

"Marc Ris" <ma*******************@ris-web.net> wrote in message
news:42**********@127.0.0.1...
Hi,

Following problem, and I can't find any solution for that:

I have an aspx page, which will (finally) generate an XLS-File which must (can) be downloaded from the user. After that, the window should close
automatically.

Well, the first part for itself is easy with Response.WriteFile().....
The second one for itself is also easy with JS window.close()

Well, combining them seems to be much complicated. The file will be
downladed, but there's no "auto-close" effect.

Any suggestions ?
WBR,
Marc

<snip>
string script = "<script language='javascript'>window.close()</script>"; Response.ClearContent();
Response.ClearHeaders();
Response.Clear();
Response.ContentType = "application/zip;filename=download.zip";
Response.AppendHeader("Content-Disposition",
"attachment;filename=download.zip");
Response.AppendHeader("Content-Length", fi.Length.ToString());
Response.WriteFile(zipFile, 0, fi.Length);
Response.Write(script);
if(!IsStartupScriptRegistered("closepopup"))
this.RegisterStartupScript("closepopup", script);
Response.Flush();
</snap>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World!
120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption

=----


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet

News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption

=----
Nov 19 '05 #4
Well, yes, it's a popup, but, also this kind of "self-reference" has no
effect.
I'm pretty sure, this has something to do with the Download-Code and its
Content-Type.
Quite annoying.

WBR,
Marc
"Eliyahu Goldin" <re*************@monarchmed.com> schrieb im Newsbeitrag
news:uF**************@TK2MSFTNGP10.phx.gbl...
Is it a popup?

Try putting

<base target=_self>

in the <head> section.

Eliyahu

"Marc" <ma*******************@ris-web.net> wrote in message
news:42**********@127.0.0.1...
Eliyahu,
Thanks for your reply.

Unfortunately, the window remains open. No effect at all. (I already tried
this earlier, and tried again now...)

WBR,
Marc
Response.Write("window.close();");

Eliyahu

"Marc Ris" <ma*******************@ris-web.net> wrote in message
news:42**********@127.0.0.1...
> Hi,
>
> Following problem, and I can't find any solution for that:
>
> I have an aspx page, which will (finally) generate an XLS-File which

must
> (can) be downloaded from the user. After that, the window should close > automatically.
>
> Well, the first part for itself is easy with Response.WriteFile()..... > The second one for itself is also easy with JS window.close()
>
> Well, combining them seems to be much complicated. The file will be
> downladed, but there's no "auto-close" effect.
>
> Any suggestions ?
> WBR,
> Marc
>
> <snip>
> string script = "<script

language='javascript'>window.close()</script>"; > Response.ClearContent();
> Response.ClearHeaders();
> Response.Clear();
> Response.ContentType = "application/zip;filename=download.zip";
> Response.AppendHeader("Content-Disposition",
> "attachment;filename=download.zip");
> Response.AppendHeader("Content-Length", fi.Length.ToString());
> Response.WriteFile(zipFile, 0, fi.Length);
> Response.Write(script);
> if(!IsStartupScriptRegistered("closepopup"))
> this.RegisterStartupScript("closepopup", script);
> Response.Flush();
> </snap>
>
>
>
> ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
News==----
> http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
> ----= East and West-Coast Server Farms - Total Privacy via Encryption =----


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet

News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+

Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption

=----


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 19 '05 #5
Hi Marc,

I had a similar problem and came across on following solution so see if you
can use it.
Quote:
It closes a popup window once the file save dialog has been closed, etiher
by saving the file or clicking cancel, etc.
GenerateCSV.asp generates a csv file using Response.ContentType =
"text/plain" and Response.AddHeader "content-disposition", "attachment;
filename=""" & fileName & """"
End Quote
This should be your page - page that creates file (download page).

First open page with following javascript code - this page will call your
download page:
<script type="text/javascript">
function getCSV(){
location.href="GenerateCSV.asp";
}
function hasFocusBack(){
if(window.focus = true)
window.self.close();

setTimeout("hasFocusBack()", 1000);
}
window.onblur = function(){
hasFocusBack();
}
</script>
....
<body onLoad="javascript:getCSV();">

The trick is, after download dialog is closed, first window gets focus
again, and then it is closed.
I tried this on aspx page and it worked.
Nov 19 '05 #6
Hi Marc,
I had a similar problem and came across to following solution. See if you
can use it.

Popup window has following javascript:
function getCSV(){
location.href="GenerateCSV.asp";
}

function hasFocusBack(){
if(window.focus = true)
window.self.close();

setTimeout("hasFocusBack()", 1000);
}

window.onblur = function(){
hasFocusBack();
}

and put in body tag: onLoad="getCSV();"

Popup window opens GenerateCSV.asp page - it can be any aspx page which
dinamically generates some file. In example I found, GenerateCSV.asp
generates a csv file using Response.ContentType = "text/plain" and
Response.AddHeader "content-disposition", "attachment; filename=""" &
fileName & """"
It is important that generated file is opened as attachment.

I hope this will help you.

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Movie Maniac? | last post by:
Hi everybody I'm writing a module for postnuke and MD-Pro to manage a subtitles section, and I'm experiencing some troubles with the download function. It works properly if I click directly...
13
by: dan roberts | last post by:
Folks, This is my first Python project so please bear with me. I need to download data from Yahoo Finance in CSV format. The symbols are provided in a text file, and the project details are...
4
by: k.mitz | last post by:
Hi, I have a PHP application that allows users to generate a .pdf report of their database content. Normally, I've had to refresh a page to call the script to generate the report, so there's a...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
2
by: Ryan Taylor | last post by:
Hello. I am trying to upload a file and save it in a Sql Server 2000 database. This seems to be working fine. However, when I download the file from SQL Server, it appears that the page that is...
5
by: Neil Rossi | last post by:
I have an issue with a particular ASP page on two web servers. Let's call these servers Dev1 and Beta1. Both Servers are running IIS 5, Windows 2000 SP4 with "almost" all of the latest patches. ...
8
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.