Forum Moderators: open

Message Too Old, No Replies

close window

How to close window

         

erenshte

12:41 pm on May 22, 2004 (gmt 0)

10+ Year Member



I have two .asp codes: one for logout, another for
exit the site.
First:
<%
session("loggedin") = false
session("username") = ""
session("email") = ""
session("alias") = ""
session("personalid") = ""
response.Redirect("index.htm")
%>
Second:
<%
if session("loggedin") = true then
session("loggedin") = false
session("username") = ""
session("email") = ""
session("alias") = ""
session("personalid") = ""
// Need to close window here
else
// Need to close window here
end if
%>

Please, advise what I have to put in the second code
to close the site.

jpjones

12:52 pm on May 22, 2004 (gmt 0)

10+ Year Member



Try outputting:


response.write("<script language=""Javascript"">")
response.write("window.close();")
response.write("</script>")

Note, if the window wasn't opened as a pop up, then you'll get a javascript prompt saying something to the effect of "A program is trying to close this window, do you accept?"

HTH,
JP

streetshirts

12:56 pm on May 22, 2004 (gmt 0)

10+ Year Member



Instead of setting all you variables to nothing how about using Session.Abandon?

I use something like this:

Session.Contents.RemoveAll()
Session.Abandon()

The advice previously given about closing the window is correct though.

erenshte

1:59 pm on May 22, 2004 (gmt 0)

10+ Year Member



Thanks, folks

The exit button is placed in the frame.
The code you suggested clears the frame.
I changed it to parent.close() or
top.close() then it clears the frame and
then closes the window prompting the user.

How to avoid the clearing the frame?

erenshte

3:01 am on May 23, 2004 (gmt 0)

10+ Year Member



Thanks, jpjones

Your suggestion works, with small changes.
The code you suggested clears the frame
where an exit button is placed in the frame.
I changed it to parent.close() or
top.close(), and now it clears the frame first
and then closes the window prompting the user.
See code below.
How to avoid the clearing the frame?

<%
if session("loggedin") = true then
session("loggedin") = false
session("username") = ""
session("email") = ""
session("alias") = ""
session("personalid") = ""
response.write("<script language=""Javascript"">")
response.write("top.close();")
response.write("</script>")
else
response.write("<script language=""Javascript"">")
response.write("top.close();")
response.write("</script>")
end if
%>

erenshte

erenshte

3:15 am on Jun 23, 2004 (gmt 0)

10+ Year Member



This is my another problem.
The following code is login processing code:
<!-- #include file="dbconn.asp" -->
<%
username = request.form("username")
password = request.form("password")
SQL = "SELECT * FROM Personal WHERE username = '" & username & "' AND password = '" & password & "'"
set rs = cn.execute(SQL)

if rs.eof then
response.redirect "login.asp?error=1"
%>
<!-- #include file="dbconnclose.asp" -->
<%
else
session("loggedin") = true
session("personalid") = rs("PersonalID")
session("alias") = rs("Alias")
session("username") = rs("Username")
SQL = "UPDATE Personal SET TimesLoggedIN = TimesLoggedIn + 1, LastLogin = Now() WHERE Alias = '" & session("alias") & "'"
response.redirect "buildmain.htm"

set ps = cn.execute(SQL)
ps.close
set ps = nothing
rs.close
set rs = nothing

end if
%>

in the login.asp file I have a login form with the following line:

<form name="form1" method="post" target="_top" action="login_proc.asp">

which opens buildmain.htm form log_proc on the
_top window if login is correct

If user makes mistake the login form is displayed
again and id should be displayed at the same
frame as before. There is an initial link from the
manu that opens login form in one of three frames,
let's call main2.

If I change target in the line above to "_self"
it solves the problem, but then buildmain.htm
opens at the same frame too.

I'm stacked with this small and possible easy
solvable problem.

Please, help

erenshte