Opening Link in new browser

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Opening Link in new browser

Post by mohson »

can anyone show me how to alther this line of code so that the link opens in a new browser.

Code: Select all

<td>'. '<a href=http://'.$row->web_url.'>'.$row->orgname . '</a></td>
I knwo you need to use target"=_blank" in some form or another but advice would be greatly appreciated.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

'<td>'. '<a href="http://'.$row->web_url.'>'.$row->orgname . '" target="_blank"</a></td>'
EDIT | Doh... didnt spot your syntax error :roll: BTW - GOOGLE
Last edited by Chris Corbyn on Tue Apr 19, 2005 5:21 am, edited 1 time in total.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Re: Opening Link in new browser

Post by vigge89 »

mohson wrote:can anyone show me how to alther this line of code so that the link opens in a new browser.

Code: Select all

<td>'. '<a href=http://'.$row->web_url.'>'.$row->orgname . '</a></td>
I knwo you need to use target"=_blank" in some form or another but advice would be greatly appreciated.

Code: Select all

<?php echo '<td>'. '<a href="http://'.$row->web_url.'" target="blank">'.$row->orgname . '</a></td>';
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

maybe im completele missing something but botth of these methods result in a blank screen it must be that im putting in an extra ' or . heres the echo statement:

Code: Select all

echo "<tr bgcolor=\"$color\"><td>".$count . '</td>
<td>'.$row->org_id.'</td>
<td>'. '<a href=http://'.$row->web_url.'>'.$row->orgname . '</a></td>
<td>'. $row->notes .'</td>
<td><a href="editorganisations.html?org_id=' .$row->org_id. '">edit</tr>';
now how would I make the link open in a new browser?

i did google it bu the problem is how I incorporate it into my code.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

make sure to quote the value of all attributes in tags. target is the proper way.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

XHTML compliant:

Code: Select all

$site = "www.google.com";
  echo "<a href=\"$site\" onclick=\"window.open(this.href,'_blank');return false;\">";
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

Todd_Z wrote:XHTML compliant:

Code: Select all

$site = "www.google.com";
  echo "<a href="$site" onclick="window.open(this.href,'_blank');return false;">";
Not really, XHTML is designed too just be viewed in a single window (no frames either), that's why the target-attribute was removed. By using JavaScript, you're just cheating, if you rally want to use target="", consider going back to XHTML 1.0 Transitional.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

The point is: the user should decide himself where/how a page/file is opened (more general handled). This makes the target attribute a bit useless, therefor i think it's removal was justified.

Imho, the javascript "work-around" is used by webmasters that still don't get that *i* and not them are in control.

Spend your time educating your users/manager so they know how the web really works instead of searching for things that are broken by design.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

I dont think that this is correct, Ok I see the point that the user should be in control but it depends on the type of application - my users are working through a list of organisations and clicking on the orgs URL link one after the other, if you click on the link and it asks you the same quetion over and over again - wouldnt this be a bir irrtitating.

Actually if you only had to do it the once and then maybe this method would be ok.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

vigge89 wrote: Not really, XHTML is designed too just be viewed in a single window (no frames either), that's why the target-attribute was removed. By using JavaScript, you're just cheating, if you rally want to use target="", consider going back to XHTML 1.0 Transitional.
Yes and no.

Yes, it was their intention that authors not be the ones controlling people's browsing style (single-window, multi-window, etc). However, they explicitly discussed javascript as being the correct replacement for that functionality. Its not cheating. Further, Transitional (by definition) is a stepping stone towards the final (strict), and will be phased out one day.

For a longer and more accurate writeup on how to use javascript to properly allow new windows in a xhtml-strict compliant site:

http://www.sitepoint.com/article/standa ... iant-world

By making it reliant on scripting, the user has control over whether to allow it or not. Simple. :)
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

The sitepoint link was great. Thanks Roja...
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

neophyte wrote:The sitepoint link was great. Thanks Roja...
Sitepoint is sometimes a mixed bag, but they have some truly fantastic articles there. I'm working on an article submission to them this month, as a matter of fact, so hopefully soon I can point at my own article there. :)
Post Reply