Click to See Complete Forum and Search --> : close window


sandro27
10-08-2004, 11:32 PM
Hi!!

I need to know a script that closes the window I have just opened after <meta http-equiv="refresh"content="5">

Hope to get some help

Cheers

Sandro27

Jona
10-08-2004, 11:44 PM
To close an opened window, use the following code.


window.close();

sandro27
10-08-2004, 11:47 PM
Do I out this code inside the html tags after content="5">?

cheers

Sandro27

Jona
10-08-2004, 11:48 PM
No, it belongs in the opened window. You can't open a new window with a META refresh, as far as I know. How do you want to close the window?

sandro27
10-08-2004, 11:54 PM
Dear Jona,

I am working with 2 windows: the main and the small one that pops out when I want to send a form.

When I send a form from the small one it confirms that the information has been sent but I need a command that after refreshing 5 seconds it automatically closes the small window.

Hope you can get the idea

Cheers

Sandro27

Jona
10-09-2004, 12:05 AM
Add a query string to the refresh command.


<meta http-equiv="Refresh" content="5; url=this_page.html?close=true">


Then add this to the HEAD tags.


<script type="text/javascript"><!--
window.onload = function(){
if(location.search.indexOf("?close=true") != -1){
self.close();
}
}
//--></script>

sandro27
10-09-2004, 12:45 AM
Dear Jona,

I have included the lines you suggested but the window keeps refreshing to itself without closing. The page is php but I have used <head> tags.

I donīt know much about JS so i am having dificult to undestand the code.

Cheers

Sandro

Jona
10-09-2004, 01:40 PM
Can you show me the code you have in the popup, please? I don't need everything in the form, or any text, but the actual form element itself and the headers would definitely help.

sandro27
10-10-2004, 07:41 PM
Dear Jona,

Thanks for your attention. The window opens with this command:

<a href="#" onclick="window.open('reply.php?id_member=<?=$lista['member_id']?>&member_id=<?=$id?>','','width=244,height=257')">Reply</a>

Then inside the new window you have (php file):

<form action="" method="post" enctype="multipart/form-data" name="form1">
<input name="first_name" type="text" id="first_name" value="<?=$lista['first_name']?>">

<textarea name="message" cols="25" rows="6" id="message"></textarea>

<input type="submit" name="submit" value="submit">

</form>

What I am trying to do is, after somebody sends a message, it says " your message has been sent sucessfully" and then it closes after letīs say 5 seconds.

I donīt know if I am trying to do something too complicated. If I am please tell me !!

Cheers

Sandro27

Jona
10-11-2004, 11:11 AM
Add a query string to the form's action.


action="<?=$_SERVER["REQUEST_URI"];?>&exit=1"


Then search for it upon page loading.


<script type="text/javascript"><!--
function checkExit(){
if(location.search.indexOf("exit=1") != -1){
window.close();
}
}
window.onload = function(){window.setTimeout("checkExit()", 5000)};
//--></script>

sandro27
10-11-2004, 08:32 PM
Dear Jona,

The window closing is working as I wanted. Thank you.

I didnīt understand how it does cuz I am donīt know much JS but I will get there.

Sandro

Jona
10-11-2004, 10:49 PM
It runs the checkExit function every 5,000 milliseconds (5 seconds). The function checks the URL for the query string "exit=1." If it finds it, it closes the window, otherwise it does nothing. You could write the code to clear the timeout and have the page run more efficiently, but it shouldn't make much of a difference at all, since most computers can handle running the same function or other functions many, many times per second.

Entertainer
10-12-2004, 04:47 AM
Hey i got a question too...

For school i have to make this webpage in javascript.... i made a standard button, and when you click on it it asks you if you want to close it...

I want to get rid of the prompting thingy, i want it to immediatly close the window without asking if this is ok or anything, could anyone help me?

javaNoobie
10-12-2004, 05:16 AM
Well you can't bypass that dialog box. However, there is a trick that was posted in this forum before to do exactly what you wanted. I'm not sure if it still works.

window.opener = self
window.opener.close();

Jona
10-12-2004, 11:15 AM
It will work, but I would highly discourage any use of it. Because the more people use it, the more widespread it will become, and then browsers will have to change things up so that the "self" property cannot be set as another window.

Entertainer
10-14-2004, 02:58 AM
Originally posted by javaNoobie
Well you can't bypass that dialog box. However, there is a trick that was posted in this forum before to do exactly what you wanted. I'm not sure if it still works.

window.opener = self
window.opener.close();


you got another idea?

btw....

<INPUT onclick="window.close()" window.opener = self
window.opener.close(); type=button align="center" value="sluit venster">

how do i fill it in?

i have it like this now but it doesn't work...

javaNoobie
10-14-2004, 03:06 AM
<INPUT onclick="window.opener = self;window.opener.close();" type="button" align="center" value="sluit venster">