Results 1 to 6 of 6

Thread: Small Problem

  1. #1
    Join Date
    Mar 2010

    Question Small Problem

    Small problem... it set up to when you click on the site link it opens in same page ... how can i get it to open in a new window.

    $sql = mysql_query("SELECT * FROM businesses WHERE id='$id'");
    while($row = mysql_fetch_array($sql)){
    $name = $row['name'];
    $info = $row['info'];
    $owner = $row['owner'];
    $site = $row['$site'];

    code Shows link on web page
    <tr><td><b>Site</b></td><td><a href='<?php echo $site; ?>'><?php echo $site; ?></a></td></tr>

  2. #2
    Join Date
    Nov 2008
    You can use the target attribute of the <a> tag. Set it to "_blank" for a new window/tab. Note that it's generally not considered very "polite" to do this these days though, and it's actually invalid according to the XHTML strict doctype, so bear that in mind if it applies to you.
    The first rule of Tautology Club is the first rule of Tautology Club.

  3. #3
    Join Date
    Mar 2010
    show ex-sample lost

  4. #4
    Join Date
    Mar 2010
    Quote Originally Posted by Mindzai View Post
    ......and it's actually invalid according to the XHTML strict doctype, so bear that in mind if it applies to you.
    To quote one of my favourite singers, Meatloaf - "You took the words right out of my mouth" (I always try to code in xhtml...but I digress)

    Anyway, an alternative is to call a javavscript function in the value of href which uses window.open() to open a url in a new window.

    There is an example of window.open() on the w3schools website at

    Last edited by tirna; 03-25-2010 at 08:43 PM.

  5. #5
    Join Date
    Mar 2010
    <tr><td><b>Site</b></td><td><a href='<?php echo $site; ?>' target='_blank'><?php echo $site; ?></a></td></tr>


  6. #6
    Join Date
    Mar 2010
    As many others around here mention a lot, make sure you filter your input/output. Placing the value directly into a link with no filtering/sanitizing will make you open to xss attacks. Even if the input is yours you should sanitize it before outputting it to the html code. You should also watch using <b> tags, they're not deprecated yet but i have a feeling they soon will be. Use css styling instead.
    And keep in mind, if you still want to be compliant, you can always attempt to make your own custom dtd, making it support target="_blank", i believe most browsers pop into standards mode still and it will validate. Though that may be more trouble than its worth.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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