Results 1 to 6 of 6

Thread: pop-up window link

  1. #1
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default pop-up window link

    i have previously used html for pop-up window:
    Code:
    <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:
    PHP Code:
    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
    Last edited by liamallan; 03-25-2010 at 12:09 AM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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:
    PHP Code:
    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:
    PHP Code:
    ?> [<a href="send.php" onClick="NewWindow(this.href,'name','600','400','yes');return false">Send Message</a>]<br><br>"; <?php
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default

    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:
    PHP Code:
    <?
    /* Requested Username error checking */
    $req_user trim($_GET['user']);
    if(!
    $req_user || strlen($req_user) == ||
       !
    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>";

    ?>

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default

    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/u...user=liamallan
    Last edited by liamallan; 03-22-2010 at 02:33 AM.

  6. #6
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Thumbs up

    its ok guys, got it sorted! had to resort to using javascript. thanks for your help anyway!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •