944,087 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Nov 4th, 2009
0

how can i make a window close itself after running the php code

Expand Post »
i know how to do the link thing that if u click it it closes the window. but im wondering if theres a way to automatically close a window after the php code is done running.
cause i have an inbox and theres a link to delete the message if you click on it it will open up a new windows and run the php script to delete the message then it will say message deleted. im wondering how instead if just saying msg deleted it can close itself(the window) as well? does anyone know how? can i do it with pure php or do i need javascript too? i figured javascript.

because the link ive come up with stuff im working on elsewhere is a javascript link to close the window.

anyone know the javascript to do this? plz helps.?
Similar Threads
Reputation Points: 15
Solved Threads: 7
Posting Pro in Training
SKANK!!!!! is offline Offline
428 posts
since Apr 2009
Nov 5th, 2009
0
Re: how can i make a window close itself after running the php code
html Syntax (Toggle Plain Text)
  1. <html><head></head><body>This is a popup window,<br>
  2. which may not open on any random system thanks to popup blockers<br>
  3. on the chance that it does open, I want to close it 5 seconds later
  4. <script type='text/javascript'>
  5. <!--
  6. settimeout('self.close()',5000);
  7. --></script></body></html>
also
html Syntax (Toggle Plain Text)
  1. <body onload="javascript:settimeout('self.close()',5000);">
Last edited by almostbob; Nov 5th, 2009 at 1:14 am.
Reputation Points: 562
Solved Threads: 368
Posting Maven
almostbob is offline Offline
2,970 posts
since Jan 2009
Nov 5th, 2009
-1
Re: how can i make a window close itself after running the php code
thanks but if i set it to 5 will it start after the code beofre it is run
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type='text/javascript'>
  2.  
  3. <!--
  4.  
  5. settimeout('self.close()',5000);
  6.  
  7. --></script>

that one. cause well i need to have the code before it run before the window closes?
Last edited by peter_budo; Nov 5th, 2009 at 7:09 pm. Reason: Correcting code tags
Reputation Points: 15
Solved Threads: 7
Posting Pro in Training
SKANK!!!!! is offline Offline
428 posts
since Apr 2009
Nov 5th, 2009
0
Re: how can i make a window close itself after running the php code
Click to Expand / Collapse  Quote originally posted by almostbob ...
html Syntax (Toggle Plain Text)
  1. <html><head></head><body>This is a popup window,<br>
  2. which may not open on any random system thanks to popup blockers<br>
  3. on the chance that it does open, I want to close it 5 seconds later
  4. <script type='text/javascript'>
  5. <!--
  6. settimeout('self.close()',5000);
  7. --></script></body></html>
also
html Syntax (Toggle Plain Text)
  1. <body onload="javascript:settimeout('self.close()',5000);">
this one isnt working for me i have javascript enabled too
Reputation Points: 15
Solved Threads: 7
Posting Pro in Training
SKANK!!!!! is offline Offline
428 posts
since Apr 2009
Nov 5th, 2009
0
Re: how can i make a window close itself after running the php code
Since you're running PHP code, the JS wil only be executed after the PHP code is run. So you can run it with or without a timeout. Simply adding the following code anywhere (valid) in the HTML page is enough,

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type='text/javascript'>
  2. self.close();
  3. </script>
Reputation Points: 13
Solved Threads: 19
Junior Poster
jomanlk is offline Offline
103 posts
since Oct 2009
Nov 5th, 2009
-1
Re: how can i make a window close itself after running the php code
lol oh mi this works a lot. i have some javascript to hide the message in the inbox onclick of the delete button . LOL i didnt even see the window open but it deleted it(fast)
the timeout didnt work for me for some reason but the just self.close works perfectly thanks!
Reputation Points: 15
Solved Threads: 7
Posting Pro in Training
SKANK!!!!! is offline Offline
428 posts
since Apr 2009
Nov 5th, 2009
0
Re: how can i make a window close itself after running the php code
Cool. Close thread please.
Reputation Points: 13
Solved Threads: 19
Junior Poster
jomanlk is offline Offline
103 posts
since Oct 2009
Nov 5th, 2009
0
Re: how can i make a window close itself after running the php code
Just a note.

Ideally though, you shouldn't be opening a popup to delete whatever it is you are deleting. You should just be redirecting to the delete page, and the delete page would redirect back to the index page.

Something like this

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. //index.php
  2. <a onclick="return confirm('Are you sure?')" href="delete.php?id=4">Delete</a>
  3.  
  4. //delete.php
  5. //Code to delete
  6. //Redirect back to index.php

This way there are no mysterious popups appearing for the user. Although it may seem fast for you (since you are running it locally). On a slow connection, the user would only see a blank popup opening and closing. He might get worried

Anyway, just some thoughts. Close this thread if you are done with it please.
Reputation Points: 13
Solved Threads: 19
Junior Poster
jomanlk is offline Offline
103 posts
since Oct 2009
Nov 5th, 2009
-1
Re: how can i make a window close itself after running the php code
Click to Expand / Collapse  Quote originally posted by jomanlk ...
Just a note.

Ideally though, you shouldn't be opening a popup to delete whatever it is you are deleting. You should just be redirecting to the delete page, and the delete page would redirect back to the index page.

Something like this

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. //index.php
  2. <a onclick="return confirm('Are you sure?')" href="delete.php?id=4">Delete</a>
  3.  
  4. //delete.php
  5. //Code to delete
  6. //Redirect back to index.php

This way there are no mysterious popups appearing for the user. Although it may seem fast for you (since you are running it locally). On a slow connection, the user would only see a blank popup opening and closing. He might get worried

Anyway, just some thoughts. Close this thread if you are done with it please.
oh i see but im not sure if its actually a popup im just using target="_blank" on my delete form,
but there is two different ways to delete messages, the first way is the open window which for me is always a tab. and then it deletes it and thats on the inbox page which target="_blank" is necassary because its easier to delete multiple messages all on one page. and then the other way which i might have to do the redirecting although am currently using the same thing which is the open page then auto close this delete button is on the message page itself. which its kind of odd i press delete and it deletes(maybe someone would press delete 5 times and not know it was deleted) so i guess ill have to redirect but i cant use target blank so what do i do. i submit the delete form and it brings the user to a page without a popup to delete. it brings the user to the delete page but it has to run through if(isset($_POST[delete])){do the php delete actions in for deleting the message from the mysql database t

but then what? i dont understand the redirecting i would use here

oh and i dont run things locally. i dont understand winamp
Last edited by SKANK!!!!!; Nov 5th, 2009 at 2:29 am.
Reputation Points: 15
Solved Threads: 7
Posting Pro in Training
SKANK!!!!! is offline Offline
428 posts
since Apr 2009
Nov 5th, 2009
0
Re: how can i make a window close itself after running the php code
You'd have this kind of setup

First the Index page
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. //fake display structure
  2. <ul>
  3. <li>Item 1 - <a onclick="return confirm('Are you sure?')" href="delete.php?id=1">Delete</a></li>
  4. <li>Item 2 - <a onclick="return confirm('Are you sure?')" href="delete.php?id=2">Delete</a></li>
  5. <li>Item 3 - <a onclick="return confirm('Are you sure?')" href="delete.php?id=3">Delete</a></li>
  6. <li>Item 4 - <a onclick="return confirm('Are you sure?')" href="delete.php?id=4">Delete</a></li>
  7. </ul>

Now the delete page
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?php
  2. $id = isset($_GET['id']) ? intval($id) : 0;
  3.  
  4. if ($id) { //just some validations
  5. //do delete commands
  6. header("Location: index.php"); //It's important that you haven't output anything upto this point
  7. }
  8. ?>

This way there are no new windows or popups.

If you want users to be able to delete multiple messages at once, you'd have to modify the code so that users can select which messages are to be deleted. You can use an array of checkboxes for this and modify the delete code to work with an array. But then you'd have to use a FORM element to submit. That's another topic, some info can be found here
Reputation Points: 13
Solved Threads: 19
Junior Poster
jomanlk is offline Offline
103 posts
since Oct 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Warning Message on Browser Close
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Get, show PDF, JPG, Video





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC