Opening ALL links in new window

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
dirgeshp
Forum Newbie
Posts: 23
Joined: Thu Jun 22, 2006 11:40 am

Opening ALL links in new window

Post by dirgeshp »

I am making a entire website and have already implemented everything...

the problem is i dont want to go to EVERY single link and add "target=_blank_"

so is there a way to make it so that EVERY link that a user clicks on in my website...it opens in a NEW WINDOW

please help
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Sorry to ask a question w/out providing an answer, but WHY whould you want to do that??
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Check out the behaviour javascript library, that would probably be the easiest solution.
dirgeshp
Forum Newbie
Posts: 23
Joined: Thu Jun 22, 2006 11:40 am

Post by dirgeshp »

Can you provide me with a link to that library
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

target is depracated. W3C recommends Javascript for that. Add the following to the <a> elements.

Code: Select all

onclick="return !window.location(this.href)"
For accessibility you should also add an identical event handler "onkeypress" for people not using a pointing device.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Not to try to sell you on a different idea, but there is an interesting article on Sitepoint regarding opening new windows with hyperlinks.

If you must open new windows, use JavaScript instead of the depricated (and XHTML non-comliant) target="_blank" attribute.
Post Reply