Log in

View Full Version : Resolved pop-up window link



liamallan
03-21-2010, 04:10 PM
i have previously used html for pop-up window:

<li><a href="http://www.shiftysplayground.co.cc/contactus.php" onClick="NewWindow(this.href,'name','600','400','yes');return false">Contact Us</a></li>
which worked fine, i have tried the same mothod within php to find it doesnt work the same:

echo "[<a href=\"send.php\" onClick="NewWindow(this.href,'name','600','400','yes');return false">Send Message</a>]<br><br>";
can anyone help me to get it to work? thanx

djr33
03-21-2010, 08:37 PM
1. Look at the actual HTML being generated. Then you can find the problem easily.
2. This appears to be a problem with escaping quotes. When using double quotes you must escape all double quotes WITHIN the string with a \. When using single quotes, you must escape all single quotes. Here, it's the double quotes:

echo "[<a href=\"send.php\" onClick=\"NewWindow(this.href,'name','600','400','yes');return false\">Send Message</a>]<br><br>";
3. When you are outputting this much HTML, sometimes it's better to just escape from PHP entirely, depending on your setup:

?> [<a href="send.php" onClick="NewWindow(this.href,'name','600','400','yes');return false">Send Message</a>]<br><br>"; <?php

liamallan
03-22-2010, 12:16 AM
thanx for the reply again mate, i tried both methods. php method was just as if it was an ordinary link, no window and when i tried escaping php all together i got no response from page (just blank). the aim is to have the link visible when viewing other peoples profile, but not visible when viewing own profile.
Here is the entire code:

<?
/* Requested Username error checking */
$req_user = trim($_GET['user']);
if(!$req_user || strlen($req_user) == 0 ||
!eregi("^([0-9a-z])+$", $req_user) ||
!$database->usernameTaken($req_user)){
die("Username not registered");
}

/* Logged in user viewing own account */
if(strcmp($session->username,$req_user) == 0){
echo "<h1>My Account</h1>";
}
/* Visitor not viewing own account */
else{
echo "<h1>User Info</h1>";
echo "[<a href=\"send.php\" onClick=\"NewWindow(this.href,'name','600','400','yes');return false\">Send Message</a>]<br><br>";

}

/* Display requested user information */
$req_user_info = $database->getUserInfo($req_user);

/* Username */
echo "<b>Username:</b> ".$req_user_info['username']."<br><br>";

/* Email */
echo "<b>Email:</b> ".$req_user_info['email']."<br><br>";

$timestamp = $req_user_info['timestamp'];

echo "<b>Last Active:</b> ".date('jS F Y \a\\t g.ia', $timestamp)." <br><br>";

/**
* Note: when you add your own fields to the users table
* to hold more information, like homepage, location, etc.
* they can be easily accessed by the user info array.
*
* $session->user_info['location']; (for logged in users)
*
* ..and for this page,
*
* $req_user_info['location']; (for any user)
*/

/* If logged in user viewing own account, give link to edit */
if(strcmp($session->username,$req_user) == 0){
echo "<br><a href=\"useredit.php\">Edit Account Information</a><br>";
}

/* Link back to main */
echo "<br>Back To [<a href=\"index.php\">Main</a>]<br>";

?>

jscheuer1
03-22-2010, 01:57 AM
If it works with ordinary HTML + ordinary javascript, it will work with PHP. The only problems that can arise in a situation like that would be if the HTML and javascript already on the page + what the PHP code outputs aren't correct to accomplish the desired goal.

If you know your PHP basics, this can easily be diagnosed by viewing the live page (or the page live in a PHP sandbox like WAMP) in the browser. Once you do that you can use the browser's 'view source' to see what is being outputted by the PHP code. If that part isn't correct, logic and/or trial and error may be used to fix the PHP part.

One should however be mindful that the problem may not lie with PHP. If it doesn't, then your existing HTML and/or javascript on or associated with the page is incorrect.

Simple really.

In any case, these sorts of things are most easily diagnosed from a live example. If you want more help:

Please post a link to a page on your site that contains the problematic code so we can check it out.

It would also be helpful to see a link to a working example that uses no PHP, such as you mention in your initial post.

liamallan
03-22-2010, 02:15 AM
initial html popup is in the 'contact us' link in menu at http://www.shiftysplayground.co.cc/

and for the php one: http://www.shiftysplayground.co.cc/userinfo.php in 'send message' link.
you may need to register, and as the link doesnt show when viewing own profile, go to my profile http://www.shiftysplayground.co.cc/userinfo.php?user=liamallan

liamallan
03-25-2010, 12:08 AM
its ok guys, got it sorted! had to resort to using javascript. thanks for your help anyway!