whats wrong here

C

Chris Geerdink

combo with PHP. what is wrong with the Javascript?

else
{
include("mysql.php");
$query1 = mysql_query("INSERT INTO gbook (naam, email, text) VALUES
('".$_POST['naam']."', '".$_POST['email']."', '".$_POST['text']."')");
?>
<script language="JavaScript">
<!--
opener.reload(true);
window.close();
//-->
</script>
<?
}
 
R

Randy Webb

Chris said:
combo with PHP. what is wrong with the Javascript?

Umm, my first guess is "It doesn't work?". Seriously, whats wrong with
it depends on what its supposed to be doing, what its doing, and what
the PHP code is adding to the page. And also, what browser/UA you are
testing it with.

else
{
include("mysql.php");
$query1 = mysql_query("INSERT INTO gbook (naam, email, text) VALUES
('".$_POST['naam']."', '".$_POST['email']."', '".$_POST['text']."')");
?>
<script language="JavaScript">

<!--

Not needed.
opener.reload(true);
window.opener.reload(true);

window.close();

The window.close() will only work in certain browsers, and only when the
page was opened via Javascript. Otherwise, you get a confirmation
telling you that script is trying to close the window.

Not needed.
 
L

Lasse Reichstein Nielsen

I agree with everything else, but there's just one thing I have to
comment on :)
window.opener.reload(true);

That shouln't be necessary. Especially in the global scope, where this
code is executed, adding one level of indirection to the access of a
global variable adds nothing except overhead.
The window.close() will only work in certain browsers, and only when
the page was opened via Javascript. Otherwise, you get a confirmation
telling you that script is trying to close the window.

But if "opener" is defined, then the page is most likely opened via
Javascript. If it isn't defined, then the previous line would error.

/L
 
R

Randy Webb

Lasse said:
I agree with everything else, but there's just one thing I have to
comment on :)




That shouln't be necessary. Especially in the global scope, where this
code is executed, adding one level of indirection to the access of a
global variable adds nothing except overhead.

True, it shouldn't be needed, but I have gotten in the habit lately of
making my references absolute just in case :-\
But if "opener" is defined, then the page is most likely opened via
Javascript. If it isn't defined, then the previous line would error.

Yes, if opener is defined...... but opener doesn't have to be defined in
certain browsers to be able to close a window that script didn't open,
and it was that exception I was silently alluding to.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top