Forum Moderators: coopster

Message Too Old, No Replies

Need [link_url] to open in new window

Is there a way to make some links in a php file open in new window

         

aodhan

4:38 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



This is a piece of code thats in a php file.

<tr><td align='center'><a href='$row[link_url]' onClick=\"javascript:window.open('waiting.php?email=$email& banner_id=$row[banner_id]& action=open','loading','toolbar=no,left=50,top=50,scrollbars=no,resizable=no,width=400,height=100,alwaysRaised=yes')\ "></a></td></tr>

I think this is the piece I need to change.
The 'waiting.php' file opens in a new window but
I want the [link_url] to open in a new window aswell.

Is there any piece of code that can be put into a php file to make links open in new window?

[edited by: jatar_k at 5:08 pm (utc) on Aug. 13, 2004]
[edit reason] fixed sidescroll [/edit]

ergophobe

8:32 pm on Aug 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You could use the attribute
target="_blank"

it's not valid in XHTML, but is fine in HTML links.

I don't believe that single quotes for attributes are valid so
align='center' should be align="center"

Also, your PHP syntax has some problems

$row[link_url] should be $row['link_url'] and so on.

You'll need to do some sorting with your quotes, but I would recommend just getting out of the strings instead of doing inline variable substitution as in

$x = '<tr><td align="center"><a href="' . $row['link_url']' . "onClick=\"javascript:window.open('waiting.php')\">Link text</a></td></tr>";

py9jmas

9:00 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



I don't believe that single quotes for attributes are valid

Single quotes are fine, it's something HTML picked up from SGML:
[w3.org...]

By default, SGML requires that all attribute values be delimited using either double quotation marks (ASCII decimal 34) or single quotation marks (ASCII decimal 39). Single quote marks can be included within the attribute value when the value is delimited by double quote marks, and vice versa.

ergophobe

12:41 am on Aug 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks. I wasn't sure. Now I am!

Tom

aodhan

10:19 am on Aug 14, 2004 (gmt 0)

10+ Year Member



Well my code actually works fine, so I dont want to change it too much. All that I want is, when clicked the [link_url] will open in new window. I tried putting : [link_url] target="_blank"....., but when I tried to open page I got : unexpected parse error.

ergophobe

2:14 pm on Aug 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If the parse error is on the page with the link and all you did was add target="_blank" the problem is no doubt because of the quote marks. Try target='_blank' or target=\"_blank\"

On the other stuff, if you set error reporting to show notices and warnings, you'll be getting them all over the place because of not quoting associative indexes. Check out the manual on arrays [us2.php.net] and read the section "Array do's and don'ts. Why is $foo[bar] wrong?".