473,796 Members | 2,512 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onunload event help

31 New Member
HI

I am trying to use the window onunload event, so that when a user closes the window it will go and delete a text file that it uses to read contents from, so to stop my server filling up with loads of text files.

But i have problem that it will go and delete a file if i push a button as it considers moving away from that page as an onunload event.

i am trying to write the function so that it can detect wether the button has been pushed or if the window has been closed

I have written the following function

Expand|Select|Wrap|Line Numbers
  1. ]function deleteFile()
  2.     {
  3.         var button1 = document.getElementById('result').click=true; 
  4.         var button2 = document.getElementById('manual').click=true; 
  5.         if (button1||button2)
  6.         {
  7.              alert("button pushed")
  8.         }
  9.         else
  10.         {
  11.             var q = new Query();
  12.             if (q.file!=null)
  13.             {
  14.                   if (q.url!=null)
  15.                     {
  16.                     var file=q.file;
  17.                      var url = q.url;
  18.                      var link="a url";
  19.                     window.opener.location=link;
  20.                     }
  21.  
  22.              }
  23.          }
  24.       }
if i push the button it says the button pushed and if i close the window it says button pushed, so its obviously not working.

any ideas?

cheers
Boyindie
Feb 14 '08 #1
6 1520
ronverdonk
4,258 Recognized Expert Specialist
This thread does not belong in the PHP forum. Should be moved to JavaScript.

Ronald
Feb 14 '08 #2
JosAH
11,448 Recognized Expert MVP
This thread does not belong in the PHP forum. Should be moved to JavaScript.

Ronald
Et voila.

kind regards,

Jos
Feb 14 '08 #3
ronverdonk
4,258 Recognized Expert Specialist
Thanks Joth.

Ronald
Feb 14 '08 #4
boyindie86
31 New Member
appologies wrong window
Feb 14 '08 #5
boyindie86
31 New Member
HI

I am trying to use the window onunload event, so that when a user closes the window it will go and delete a text file that it uses to read contents from, so to stop my server filling up with loads of text files.

But i have problem that it will go and delete a file if i push a button as it considers moving away from that page as an onunload event.

i am trying to write the function so that it can detect wether the button has been pushed or if the window has been closed

I have written the following function

Expand|Select|Wrap|Line Numbers
  1. ]function deleteFile()
  2.     {
  3.         var button1 = document.getElementById('result').click=true; 
  4.         var button2 = document.getElementById('manual').click=true; 
  5.         if (button1||button2)
  6.         {
  7.              alert("button pushed")
  8.         }
  9.         else
  10.         {
  11.             var q = new Query();
  12.             if (q.file!=null)
  13.             {
  14.                   if (q.url!=null)
  15.                     {
  16.                     var file=q.file;
  17.                      var url = q.url;
  18.                      var link="a url";
  19.                     window.opener.location=link;
  20.                     }
  21.  
  22.              }
  23.          }
  24.       }
if i push the button it says the button pushed and if i close the window it says button pushed, so its obviously not working.

any ideas?

cheers
Boyindie
Feb 14 '08 #6
acoder
16,027 Recognized Expert Moderator MVP
Threads merged. If your thread was moved, there was no need to post again.

You can't really detect window close, but if you are going to base it on the button being pressed, set the variable when you click the button (onclick) and then test for it. At the moment, you're always setting it to true.
Feb 14 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
7729
by: Brian Vallelunga | last post by:
I'm working on an asp.net site and am trying to implement a popup help window. I want the window to close when the user advances to the next page in our application. The thing is, I'm doing this on a component basis and I don't have access to the body tag from within my help component, so I can't add the onunload tag. Is there some other way of achieving what I want? Can I add an eventhandler to the body tag through javascript? Thanks, ...
3
8571
by: Andoni | last post by:
Hi, I am only writing for IE 5.5+ so no need for compatibility at all ;-) I am trying to get my users to logoff which they finish on a particular page. This is no problem (or should be no problem) as I can just put a location.replace('http://www.mysite.com/html/logoff.jsp'); into the onUnload event of the page they always finish on. This should fire when they click the X in the corner (my app. is in a popup window) instead of hitting...
3
6971
by: Laurent | last post by:
I am trying to use the onunload event to know when the user closes a popup by receiving a request on the web server. I have a main page from where the user opens a popup. What I want is when the user closes the popup, it sends a request to my web server (GoAhead) using the onunload event, then closes the popup. For the moment, this what i have: when the user closes the popup, I use the onunload event to open a different popup (by this...
5
5021
by: Viktor Popov | last post by:
Hi, Iwould like to do that. Is it possible because I can't do it? in test.aspx file: <body onunload="signout()"> in test aspx.cs : void private signout() { HttpContext.Current.Cache.Remove(Session.ToString());
3
5877
by: =B= | last post by:
Hi all, I was wondering if anyone has had any luck with trapping the <BODY> onUnload() event in ASP.NET? The thing is, I'm writing code for an Intranet site. The code makes a call to a third-party component (think of it as a lock) when the page loads. Now the OK and Cancel server buttons I can handle and use to release the lock as required. But previously in classic ASP I had been trapping the user hitting the close 'x' button by...
1
3920
by: Angel | last post by:
I am trying to capture when the user clicks the X button on the ie window. I have used the onunload for the window event, but there is a problem. I put javascript code for this event and when the form performs a postback on the page, the onunload event gets triggered eventhough I am still on the same page and the user did not click the 'X' button. In other words, the onunload event is triggered when you are performing a postback to the...
1
5328
by: Laurent Bugnion | last post by:
Hi, I am trying to programatically add an "onunload" event handler to the "body" tag of an ASPX page. I am doing this from a Custom Control located on this page. To do this, I added "runat=server" to the body tag, which provides me access to it in the code-behind through a HtmlControl. I can then manipulate the Attributes collection, which is what I needed. So far so good.
7
2924
by: tgh003 | last post by:
I have been at this for hours now. Pulling my hair out. I have a standard php page that has an onunload event on it. The onunload event sends a xmlhttprequest that triggers a database update, for simplicity lets say it updates a table: UPDATE testtable SET testfield = '".$_GET."' where id = 1 This works just fine. Then the next page you navigate to is supposed to call the testfield
1
1528
by: Tim Arview | last post by:
Hi, I'm trying to create an exit popup that doesn't require anything added to the body tag. In other words, I don't want to say <body onunload="foo">. I just want to have window.onunload="foo" in the <scripttag. However, when I do that, it launches foo as soon as the page loads and does NOT launch when the page is unloaded.
0
9525
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10452
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10169
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.