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

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Apr 2009
Posts: 279
Reputation: SKANK!!!!! is an unknown quantity at this point 
Solved Threads: 2
SKANK!!!!! SKANK!!!!! is offline Offline
Posting Whiz in Training

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

 
0
  #1
18 Days Ago
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.?
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,308
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 161
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso
 
0
  #2
18 Days Ago
  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
  1. <body onload="javascript:settimeout('self.close()',5000);">
Last edited by almostbob; 18 Days Ago at 1:14 am.
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 279
Reputation: SKANK!!!!! is an unknown quantity at this point 
Solved Threads: 2
SKANK!!!!! SKANK!!!!! is offline Offline
Posting Whiz in Training
 
-1
  #3
18 Days Ago
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; 17 Days Ago at 7:09 pm. Reason: Correcting code tags
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 279
Reputation: SKANK!!!!! is an unknown quantity at this point 
Solved Threads: 2
SKANK!!!!! SKANK!!!!! is offline Offline
Posting Whiz in Training
 
0
  #4
18 Days Ago
Originally Posted by almostbob View Post
  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
  1. <body onload="javascript:settimeout('self.close()',5000);">
this one isnt working for me i have javascript enabled too
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 99
Reputation: jomanlk is an unknown quantity at this point 
Solved Threads: 18
jomanlk jomanlk is offline Offline
Junior Poster in Training
 
0
  #5
18 Days Ago
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>
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 279
Reputation: SKANK!!!!! is an unknown quantity at this point 
Solved Threads: 2
SKANK!!!!! SKANK!!!!! is offline Offline
Posting Whiz in Training
 
-1
  #6
18 Days Ago
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!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 99
Reputation: jomanlk is an unknown quantity at this point 
Solved Threads: 18
jomanlk jomanlk is offline Offline
Junior Poster in Training
 
0
  #7
18 Days Ago
Cool. Close thread please.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 99
Reputation: jomanlk is an unknown quantity at this point 
Solved Threads: 18
jomanlk jomanlk is offline Offline
Junior Poster in Training
 
0
  #8
18 Days Ago
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 279
Reputation: SKANK!!!!! is an unknown quantity at this point 
Solved Threads: 2
SKANK!!!!! SKANK!!!!! is offline Offline
Posting Whiz in Training
 
-1
  #9
18 Days Ago
Originally Posted by jomanlk View Post
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!!!!!; 18 Days Ago at 2:29 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 99
Reputation: jomanlk is an unknown quantity at this point 
Solved Threads: 18
jomanlk jomanlk is offline Offline
Junior Poster in Training
 
0
  #10
18 Days Ago
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
Reply With Quote Quick reply to this message  
Reply


This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC