Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inline or attachment

Status
Not open for further replies.

MaddogC

Programmer
Dec 4, 2003
134
GB
I want my user to download a file

to Achieve this I have the following:

Response.AddHeader "content-disposition", "attachment;filename=Download.csv"

A dialog box pops up and the user can save the file. Once this is done however I want to automatically close the download.asp page. How can I do this?

I have changed the addheader command to inline instead of attachment, which works nicely. There is a knock on problem then however that when the file appears in excel it's puts all the comma separated data in one cell! How can I get round this?
 
this is the javascript function that will close your page automatically...

Code:
<script language="JavaScript">
// Set the following variable to the number of seconds the browser
// will wait before closing the window.
var gWindowCloseWait = 2;

function SetupWindowClose()
{
	window.setTimeout("window.close()",gWindowCloseWait*1000);
}

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{
	isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
	IEmac = ((document.all)&&(isMac)) ? true : false;
	IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
	if (IEmac && IE4)  // IE 4.5 blows out on testing window.onload
	{
		window.onload = SafeOnload;
		gSafeOnload[gSafeOnload.length] = f;
	}
	else if  (window.onload)
	{
		if (window.onload != SafeOnload)
		{
			gSafeOnload[0] = window.onload;
			window.onload = SafeOnload;
		}		
		gSafeOnload[gSafeOnload.length] = f;
	}
	else
		window.onload = f;
}
function SafeOnload()
{
	for (var i=0;i<gSafeOnload.length;i++)
		gSafeOnload[i]();
}

// Call the following with your function as the argument
SafeAddOnload(SetupWindowClose);

</script>

-DNG
 
i think you have two questions in your original post...that was the answer for your first question..put that script the end of your page so that it executes after file downloading process is done...

let me look at your second question...

-DNG
 
oh ok...so if you could close the page automatically then i dont think there is need to solve second question...

let me know how it works for you

-DNG
 
No Luck I'm afraid. The window didn't close and the csv file that is displayed in Excel is shown as a comma separated file, where as before the values were in individual cells.

If I don't need to check for the browser type can I not just put

<script language="JavaScript">
window.setTimeout("window.close()",2000);
</script>
 
where did you actually put the code...show us the skeleton of your code...i mean may be something like this...


'database connection

'creating the csv file

'javascript code

-DNG
 
<%

Response.AddHeader "content-disposition", "attachment;filename=Download.csv"

OpenConnectionReference
SQL_Query = strSTATEMENT
RunQueryRef(strSTATEMENT)

Head=" "
Dim F, Head
For Each F In RSref.Fields
Head = Head & "," & F.Name
Next
Head = Mid(Head,3) & vbCrLf
Response.ContentType = "text/plain"
Response.Write Head
Response.Write RSref.GetString(,,",",vbCrLf,"")

CloseRSREF()
CloseConnectionRef()

%>

<script language="JavaScript">
// Set the following variable to the number of seconds the browser
// will wait before closing the window.
var gWindowCloseWait = 2;

function SetupWindowClose()
{
window.setTimeout("window.close()",gWindowCloseWait*1000);
}

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
if (IEmac && IE4) // IE 4.5 blows out on testing window.onload
{
window.onload = SafeOnload;
gSafeOnload[gSafeOnload.length] = f;
}
else if (window.onload)
{
if (window.onload != SafeOnload)
{
gSafeOnload[0] = window.onload;
window.onload = SafeOnload;
}
gSafeOnload[gSafeOnload.length] = f;
}
else
window.onload = f;
}
function SafeOnload()
{
for (var i=0;i<gSafeOnload.length;i++)
gSafeOnload();
}

// Call the following with your function as the argument
SafeAddOnload(SetupWindowClose);

</script>


 
is it like this...

<html>
<head>
</head>

<body>
<%
'asp code
%>
</body>
<javascript>
codehere
</javascript>
</html>

-DNG
 
my code now reads, but still no luck:

<html>
<head>
</head>
<body>

<%

Response.AddHeader "content-disposition", "attachment;filename=Download.csv"

OpenConnectionReference
SQL_Query = strSTATEMENT
RunQueryRef(SQL_Query)

Head=" "
Dim F, Head
For Each F In RSref.Fields
Head = Head & "," & F.Name
Next
Head = Mid(Head,3) & vbCrLf
Response.ContentType = "text/plain"
Response.Write Head
Response.Write RSref.GetString(,,",",vbCrLf,"")

CloseRSREF()
CloseConnectionRef()

%>
</body>
<script language="JavaScript">
// Set the following variable to the number of seconds the browser
// will wait before closing the window.
var gWindowCloseWait = 2;

function SetupWindowClose()
{
window.setTimeout("window.close()",gWindowCloseWait*1000);
}

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
if (IEmac && IE4) // IE 4.5 blows out on testing window.onload
{
window.onload = SafeOnload;
gSafeOnload[gSafeOnload.length] = f;
}
else if (window.onload)
{
if (window.onload != SafeOnload)
{
gSafeOnload[0] = window.onload;
window.onload = SafeOnload;
}
gSafeOnload[gSafeOnload.length] = f;
}
else
window.onload = f;
}
function SafeOnload()
{
for (var i=0;i<gSafeOnload.length;i++)
gSafeOnload();
}

// Call the following with your function as the argument
SafeAddOnload(SetupWindowClose);

</script>

</html>


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top