954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

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

SKANK!!!!!
Posting Pro in Training
429 posts since Apr 2009
Reputation Points: 15
Solved Threads: 7
 
<html><head></head><body>This is a popup window,
which may not open on any random system thanks to popup blockers
on the chance that it does open, I want to close it 5 seconds later
<script type='text/javascript'>
<!--
settimeout('self.close()',5000);
--></script></body></html>


also

<body onload="javascript:settimeout('self.close()',5000);">
almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

thanks but if i set it to 5 will it start after the code beofre it is run

<script type='text/javascript'>

<!--

settimeout('self.close()',5000);

--></script>


that one. cause well i need to have the code before it run before the window closes?

SKANK!!!!!
Posting Pro in Training
429 posts since Apr 2009
Reputation Points: 15
Solved Threads: 7
 
<html><head></head><body>This is a popup window,
which may not open on any random system thanks to popup blockers
on the chance that it does open, I want to close it 5 seconds later
<script type='text/javascript'>
<!--
settimeout('self.close()',5000);
--></script></body></html>

also

<body onload="javascript:settimeout('self.close()',5000);">


this one isnt working for me i have javascript enabled too

SKANK!!!!!
Posting Pro in Training
429 posts since Apr 2009
Reputation Points: 15
Solved Threads: 7
 

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,

<script type='text/javascript'>
     self.close();
</script>
jomanlk
Junior Poster
106 posts since Oct 2009
Reputation Points: 13
Solved Threads: 19
 

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!

SKANK!!!!!
Posting Pro in Training
429 posts since Apr 2009
Reputation Points: 15
Solved Threads: 7
 

Cool. Close thread please.

jomanlk
Junior Poster
106 posts since Oct 2009
Reputation Points: 13
Solved Threads: 19
 

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

//index.php
<a onclick="return confirm('Are you sure?')" href="delete.php?id=4">Delete</a>

//delete.php
//Code to delete
//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.

jomanlk
Junior Poster
106 posts since Oct 2009
Reputation Points: 13
Solved Threads: 19
 

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

//index.php
<a onclick="return confirm('Are you sure?')" href="delete.php?id=4">Delete</a>

//delete.php
//Code to delete
//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

SKANK!!!!!
Posting Pro in Training
429 posts since Apr 2009
Reputation Points: 15
Solved Threads: 7
 

You'd have this kind of setup

First the Index page

//fake display structure
<ul>
	<li>Item 1 - <a onclick="return confirm('Are you sure?')" href="delete.php?id=1">Delete</a></li>
	<li>Item 2 - <a onclick="return confirm('Are you sure?')" href="delete.php?id=2">Delete</a></li>
	<li>Item 3 - <a onclick="return confirm('Are you sure?')" href="delete.php?id=3">Delete</a></li>
	<li>Item 4 - <a onclick="return confirm('Are you sure?')" href="delete.php?id=4">Delete</a></li>
</ul>


Now the delete page

<?php 
	$id	= isset($_GET['id']) ? intval($id) : 0;

	if ($id) { //just some validations
		//do delete commands
		header("Location: index.php"); //It's important that you haven't output anything upto this point
	}
?>


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

jomanlk
Junior Poster
106 posts since Oct 2009
Reputation Points: 13
Solved Threads: 19
 

You'd have this kind of setup

First the Index page

//fake display structure
<ul>
	<li>Item 1 - <a onclick="return confirm('Are you sure?')" href="delete.php?id=1">Delete</a></li>
	<li>Item 2 - <a onclick="return confirm('Are you sure?')" href="delete.php?id=2">Delete</a></li>
	<li>Item 3 - <a onclick="return confirm('Are you sure?')" href="delete.php?id=3">Delete</a></li>
	<li>Item 4 - <a onclick="return confirm('Are you sure?')" href="delete.php?id=4">Delete</a></li>
</ul>

Now the delete page

<?php 
	$id	= isset($_GET['id']) ? intval($id) : 0;

	if ($id) { //just some validations
		//do delete commands
		header("Location: index.php"); //It's important that you haven't output anything upto this point
	}
?>

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


im afraid header wont work here. but maybe ill try it. oh just tried it LOL im pretty sure im looking for a javascript redirect but im just confused how am i supposed to make it so that liike the thing knows where it got deleted from cause im keeping the inbox the way it is i just need to change the message page so it redirects i dont think header will work here myabe i use a variable on the other one so if deleting from inbox : do this and if not: do the redirecting i assume.
i just need to remember than darn redirect code... with js. dangit

SKANK!!!!!
Posting Pro in Training
429 posts since Apr 2009
Reputation Points: 15
Solved Threads: 7
 

The header used there is the PHP header command, It will work. If you need to know where you came from you can pass a variable or look at th PHP referrer. Javascript won't help you there I'm afraid.

Anyway, these were just some tips, you don't need to switch to it if it messes up your existing code. As long as it gets the job done :)

jomanlk
Junior Poster
106 posts since Oct 2009
Reputation Points: 13
Solved Threads: 19
 

even you can try this code in any filter like in if else
echo'';

manishmannan
Junior Poster in Training
58 posts since Nov 2009
Reputation Points: 10
Solved Threads: 4
 

ok no thats alreayd been stated before. but LOL the header actually did work... thanks im closing this cause u guys all helped a lot thanks again!

SKANK!!!!!
Posting Pro in Training
429 posts since Apr 2009
Reputation Points: 15
Solved Threads: 7
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: