onunload event help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • boyindie86
    New Member
    • Jun 2007
    • 31

    onunload event help

    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

    Code:
    ]function deleteFile()
    	{
    	    var button1 = document.getElementById('result').click=true; 
    	    var button2 = document.getElementById('manual').click=true; 
    		if (button1||button2)
    		{
    	 		alert("button pushed")
    		}
    		else
    		{
    			var q = new Query();
    			if (q.file!=null)
    			{
    	 		 	if (q.url!=null)
    	   		 	{
    					var file=q.file;
    			 		var url = q.url;
    			 		var link="a url";
    					window.opener.location=link;
    	   		 	}
    	   		 
    	 		}
    		 }
    	  }
    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
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    This thread does not belong in the PHP forum. Should be moved to JavaScript.

    Ronald

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by ronverdonk
      This thread does not belong in the PHP forum. Should be moved to JavaScript.

      Ronald
      Et voila.

      kind regards,

      Jos

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Thanks Joth.

        Ronald

        Comment

        • boyindie86
          New Member
          • Jun 2007
          • 31

          #5
          appologies wrong window

          Comment

          • boyindie86
            New Member
            • Jun 2007
            • 31

            #6
            onunload event

            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

            Code:
            ]function deleteFile()
            	{
            	    var button1 = document.getElementById('result').click=true; 
            	    var button2 = document.getElementById('manual').click=true; 
            		if (button1||button2)
            		{
            	 		alert("button pushed")
            		}
            		else
            		{
            			var q = new Query();
            			if (q.file!=null)
            			{
            	 		 	if (q.url!=null)
            	   		 	{
            					var file=q.file;
            			 		var url = q.url;
            			 		var link="a url";
            					window.opener.location=link;
            	   		 	}
            	   		 
            	 		}
            		 }
            	  }
            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

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              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.

              Comment

              Working...