www.webdeveloper.com
Results 1 to 6 of 6

Thread: Small Problem

  1. #1
    Join Date
    Mar 2010
    Posts
    12

    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.

    code:
    $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
    Posts
    2,477
    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.

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

  4. #4
    Join Date
    Mar 2010
    Posts
    2,803
    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

    http://www.w3schools.com/jsref/met_win_open.asp
    Last edited by tirna; 03-25-2010 at 08:43 PM.

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

    Close!

  6. #6
    Join Date
    Mar 2010
    Posts
    672
    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



Recent Articles