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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing Window

Status
Not open for further replies.

spacehawk

Programmer
May 17, 2000
30
US
Is there an asp command that will close the current window?

I don't want to click to close it, I just want it to close automatically when it reaches this point in the page.
 
Use "window.close()" . This is a Javascript code. So you will need to write it out to the browser using the "Response" object if you are using VBScript in ASP
 
Im trying to use this method to close a window if a cookie value is set to yes...

response.write just types that close window function in the browser window...

heres my code:

<%
If Request.Cookies(&quot;Completed&quot;) = &quot;Yes&quot; Then
response.write(&quot;window.close()&quot;)
Else
End If

%>

how do I get it to close if that cookie value exists????!!!!

 
Write the javascript into the body onLoad tag like so:
Code:
<%
If Request.Cookies(&quot;Completed&quot;) = &quot;Yes&quot; Then 
   response.write(&quot;<body onLoad='window.close();'>&quot;) 
Else
   response.Write(&quot;<body>&quot;)
End If
%>

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
thanks for your help - that worked great... now if I wanted to run a small piece of javascript (pop up window) ONLY if that same cookie value was NOT set to yes, how would that be structured - the things I keep trying keeps generating syntax errors...

heres the javascript IM using to open the window:

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function Start(URL, WIDTH, HEIGHT) {
windowprops = &quot;left=50,top=50,width=&quot; + WIDTH + &quot;,height=&quot; + HEIGHT;
preview = window.open(URL, &quot;preview&quot;, windowprops);
if (closetime) setTimeout(&quot;preview.close();&quot;, closetime*1000);
}

function doPopup() {
url = &quot;secure/survey/index.asp&quot;;
width = 670; // width of window in pixels
height = 530; // height of window in pixels
delay = 1; // time in seconds before popup opens
timer = setTimeout(&quot;Start(url, width, height)&quot;, delay*1000);
</SCRIPT>
 
What are the syntax errors you are getting?

Thanks,

Gabe
 
Actually its just running the javascript each time - without paying attention to the cookie status/value...

heres what I tried:

<%
If Request.Cookies(&quot;Completed&quot;) = &quot;Yes&quot; Then %>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>


<!-- Begin
closetime = 0; // Close window after __ number of seconds?
// 0 = do not close, anything else = number of seconds

function Start(URL, WIDTH, HEIGHT) {
windowprops = &quot;left=50,top=50,width=&quot; + WIDTH + &quot;,height=&quot; + HEIGHT;
preview = window.open(URL, &quot;preview&quot;, windowprops);
if (closetime) setTimeout(&quot;preview.close();&quot;, closetime*1000);
}

function doPopup() {
url = &quot;secure/survey/index.asp&quot;;
width = 670; // width of window in pixels
height = 530; // height of window in pixels
delay = 1; // time in seconds before popup opens
timer = setTimeout(&quot;Start(url, width, height)&quot;, delay*1000);
}
// End -->
</script>

<% Else
response.redirect(&quot;2ndpage.asp&quot;)
End If
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top