Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: auto closing a window


Message #1 by "Pete Moss" <peter.moss@o...> on Wed, 9 Oct 2002 13:37:47
What I need to do is create an ASP page that opens, executes some 
database functions and closes automaticlly. I have used some javascript 
such as self.close() and window.close, but these bring a message up 
saying the following

The web page you are viewing is trying to close the window.
Do you want to close this window?

How can i close a window with this message box being displayed

Thanks in advance
Message #2 by "Rasmus Pedersen" <rp@m...> on Wed, 9 Oct 2002 14:47:06 +0200
Hi

Why do you need to open a new window for that??
ASP is serverside so you can just excute it on the top of your page - 
before all the HTML contens.

If you need to escute this from more pages you can use the include 
feature: <!--#include file=3D"filename.asp"--> then this code will be 
executed, serversider, before anything else.

regards

Rasmus Lund Pedersen :-)
Senior Programmer
email: rp@m...
----- Original Message -----
From: "Pete Moss" <peter.moss@o...>
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Wednesday, October 09, 2002 1:37 PM
Subject: [asp_web_howto] auto closing a window


> What I need to do is create an ASP page that opens, executes some
> database functions and closes automaticlly. I have used some 
javascript
> such as self.close() and window.close, but these bring a message up
> saying the following
>
> The web page you are viewing is trying to close the window.
> Do you want to close this window?
>
> How can i close a window with this message box being displayed
>
> Thanks in advance
>
> ---
>
> Improve your web design skills with these new books from Glasshaus.
>
> Usable Web Menus
> 
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3Dnosim/theprogramm
e
> r-20
> Constructing Accessible Web Sites
> 
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3Dnosim/theprogramm
e
> r-20
> Practical JavaScript for the Usable Web
> 
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3Dnosim/theprogramm
e
> r-20
>


Message #3 by "Pete Moss" <peter.moss@o...> on Wed, 9 Oct 2002 14:12:49
> Hi

Why do you need to open a new window for that??
ASP is serverside so you can just excute it on the top of your page - 
before all the HTML contens.

If you need to escute this from more pages you can use the include 
feature: <!--#include file=3D"filename.asp"--> then this code will be 
executed, serversider, before anything else.

regards

Rasmus Lund Pedersen :-)
Senior Programmer
email: rp@m...

Thanks for replying Rasmus

I know how to use the include file section, but in more detail heres what 
i am trying to do

I have a shopping cart programmed with asp. It is attached to a database 
so when you go throught the web site, all your products are stored in 
this databse. It works by storing the id in the database and when you go 
to the shopping cart it pulls out all the products that match up with the 
current sessiopn id. When a user closes the page using the cross in the 
top right hand corner of the page, with out ordering anything, i need to 
be able to make the page delete the records from a database when this 
occurs.

Thanks




Message #4 by "Rasmus Pedersen" <rp@m...> on Wed, 9 Oct 2002 15:32:30 +0200
Hi

Why don't you dont do this in the global.asa file.

ex. global.asa

<SCRIPT LANGUAGE=3DVBScript RUNAT=3DServer>
Sub Application_OnStart
    ' Code to execute when the application starts (the server)
End Sub

Sub Application_OnEnd
    ' Code to execute when the application stops(the server)
End Sub

Sub Session_OnStart
    ' Code to execute when session begins
End Sub

Sub Session_OnEnd
    ' Code to execute when session ends
End Sub
</SCRIPT>

The Session_OnEnd is fired when the user session is ended or is timeout 
(normaly after 20 min.)

One issue here is that you will not be able to test this - you have to 
monitor the database to see if the changes happens ! :-)

Another thing you could do was to use the global.asa to excute code on a 
specifik time interval.

This exampel show a globla.asa which checks in a text file when it has 
been run, if the file don't exist it run the script. If the file exist 
it checks for is there has gone more thant 24 hours since lastrun, if so 
execute the code.

exampel:

<script language=3D=94VBScript=94 runat=3D=94server=94>
Sub Application_OnStart
End Sub

Sub Application_OnEnd
End Sub

Sub Session_OnStart
    Dim objFS
    Dim objFile
    Dim dtmTimestamp
    Dim strMappedFile

    strMappedFile =3D Server.MapPath(=94/lastrun.txt=94)
    Set objFS =3D Server.CreateObject(=94Scripting.FilesystemObject=94)
    If objFS.FileExists(strMappedFile) Then
        Set objFile =3D objFS.OpenTextFile(strMappedFile)
        dtmTimestamp =3D objFile.ReadLine
        objFile.Close
        Set objFile =3D Nothing

        If DateDiff(=94h=94, dtmTimestamp, Now) > 24 Then
            Call CleanUpCode()
            Call WriteFile(objFS, strMappedFile)
        End If
    Else
        Call CleanUpCode()
        Call WriteFile(objFS, strMappedFile)
    End If

    Set objFS =3D Nothing
End Sub

Sub Session_OnEnd
End Sub

Sub CleanUpCode
    =92 Code for clean up
End Sub

Sub WriteFile(byRef objFS, byVal strMappedFile)
    Dim objFile
    Set objFile =3D objFS.CreateTextFile(strMappedFile)
    objFile.WriteLine(Now)
    objFile.Close
    Set objFile =3D Nothing
End Sub
</script>

Regards

Rasmus Lund Pedersen
Senior Programmer
email: rp@m...
----- Original Message -----
From: "Pete Moss" <peter.moss@o...>
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Wednesday, October 09, 2002 2:12 PM
Subject: [asp_web_howto] Re: auto closing a window


> > Hi
>
> Why do you need to open a new window for that??
> ASP is serverside so you can just excute it on the top of your page - 
=3D
> before all the HTML contens.
>
> If you need to escute this from more pages you can use the include =3D
> feature: <!--#include file=3D3D"filename.asp"--> then this code will 
be =3D
> executed, serversider, before anything else.
>
> regards
>
> Rasmus Lund Pedersen :-)
> Senior Programmer
> email: rp@m...
>
> Thanks for replying Rasmus
>
> I know how to use the include file section, but in more detail heres 
what
> i am trying to do
>
> I have a shopping cart programmed with asp. It is attached to a 
database
> so when you go throught the web site, all your products are stored in
> this databse. It works by storing the id in the database and when you 
go
> to the shopping cart it pulls out all the products that match up with 
the
> current sessiopn id. When a user closes the page using the cross in 
the
> top right hand corner of the page, with out ordering anything, i need 
to
> be able to make the page delete the records from a database when this
> occurs.
>
> Thanks
>
>
>
>
>
> ---
>
> Improve your web design skills with these new books from Glasshaus.
>
> Usable Web Menus
> 
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3Dnosim/theprogramm
e
> r-20
> Constructing Accessible Web Sites
> 
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3Dnosim/theprogramm
e
> r-20
> Practical JavaScript for the Usable Web
> 
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3Dnosim/theprogramm
e
> r-20
>



  Return to Index