javascript/php interaction issue

They have: 461 posts

Joined: Jul 2003

ok suanne... how do i get this to work? (echoline has added returns to stop scrolling)

<?php
  
if(count($ims)){ # if there's any ims
   
echo \"\n      &lt;script language=\\"javascript\\"&gt;\n\";
    foreach(
$ims as $im){ # foreach im to display
     
$mid=$im[0]; $to=$im[1]; // message id and who to reply to
      echo \"    window.open('http://24.91.157.113/findyourdesire/message.php?mid=
$mid&to=$to',
'
$mid', 'height=250,width=514,scrollbars=auto,resizable=yes');\n\";
    }
    echo \"      &lt;/script&gt;\n\";
  }
}
?>
there's no way to stop it from being in php like that. at least not theat i can think of.

the issue is that it's nto actually popping up the messages. whether i put that in the area, before the (like i've noticed ftj, rmb and several other sites do) or in the body.

i've tested all three places in plain html and in all three places it works perfectly. so i don't understand the problem here.

since you found the solution to the last one, i figured you might have some insight here

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

You want the window to open automatically? Or are you trying to write a link?

Show me how you have it in the HTML that actually works.

Frankly, I'd put a function in the header and then print a link unless I needed to have everything open automatically, then I'd write the function in the header via PHP.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Assuming you want to open it automatically, when the page loads or refreshes...

<?php
<head>

// get your variable information with your function here
// this is just for example
$mid = '4';
$to = '3';


&
lt;script type=\"text/javascript\"&gt;
// get the variables from PHP and set them in the JavaScript
var Tmid = =
$mid;
var Tto = =
$to;
var newUrl = 'http://24.91.157.113/findyourdesire/message.php?mid=' + Tmid + '&to=' + Tto;
var newWin;

// set the function to open the window
function popUp(page, name, details) {
newWin=window.open(newUrl,Tmid, 'height=250,width=514,scrollbars=auto,resizable=yes');
newWin.focus();
return false;
}
&lt;/script&gt;
</head>
?>

And then:

<?php
<body onload=\"popUp()\">
?>

However, if people have popup windows blocked they will never receive these bits from your site. It's always good to have a redundant link somewhere. Such as:

<?php
<a href=\"/url/for/message/centre.php\" onclick=\"return popUp()\">get messages</a>
?>

Anyway, you need to write the JavaScript in a sensible way, write it first, then you can pass information to it. You can't just throw in instructions without context.

They have: 461 posts

Joined: Jul 2003

i didn't even think of that. i want it to go automatically and i'm testing in mozilla but i tested the javascript in IE.... my mozilla has pop ups turned off UNLESS otherwise noted. it might very well be that. lol. let me check

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

They have: 461 posts

Joined: Jul 2003

hmmm.. turn off the pop up suppression and it works perfectly! apparently you were completely right. and i DEFINITELY need to do two things on the index: tell people how to turn on pop ups for my site via mozilla, (and if i have friends using opera and others find out on those) as well as to mention javascript is used.

and... make a link at the top of the page incase the pop up was missed

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.