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

<html><head></head><body>This is a popup window,<br>
which may not open on any random system thanks to popup blockers<br>
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);">

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?

<html><head></head><body>This is a popup window,<br>
which may not open on any random system thanks to popup blockers<br>
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

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>

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!

Cool. Close thread please.

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.

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

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

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

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 :)

even you can try this code in any filter like in if else
echo'<script=javascript>window.close();</script>';

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!

This is an example of JavaScript automatic popup closing after 3 seconds with countdown,

<p style="text-align:center">This window will close automatically within <span id="counter">3</span> second(s).</p> <script type="text/javascript">

 function countdown() {

    var i = document.getElementById('counter');

    i.innerHTML = parseInt(i.innerHTML)-1;

 if (parseInt(i.innerHTML)<=0) {

  window.close();

 }

}

setInterval(function(){ countdown(); },1000);

</script>

I have found it here. Hope this will be helpful for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.