Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
What is the PHP way of saying this?
Old 05-09-2009, 07:19 PM What is the PHP way of saying this?
Super Talker

Posts: 101
Trades: 0
Hi,

I don't know PHP and would greatly appreciate if anyone can tell me the code to say this:

HTML Code:
if this link then open in new window 

else

open in same window
My intention is to open all links leading to a particular page on my site to open in a new window and all other links to open in the same window. I can't use target_blank because I already made the links and there are just too many to go back and edit them all.
Towhid is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-09-2009, 07:49 PM Re: What is the PHP way of saying this?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
I don't think PHP is the answer in this case. PHP doesn't have any control over whether a link opens in a new window or in the same one. A browser opens a link in a new windows when it reads target="_blank" in the markup; it never sees any PHP code.

You may be able to hack together some javascript to do this, but your best bet would be to use find and replace to change all of the links to target="_blank".
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-09-2009, 08:23 PM Re: What is the PHP way of saying this?
racer x's Avatar
Ultra Talker

Posts: 457
Name: Randy
Location: Northern Wisconsin
Trades: 0
Agreed with NullPointer, if you have any javascript experience (or even easier, jQuery experience) it wouldn't be that hard to append a target="_blank" to specified anchors with a common class.

However, if you don't have these targeted anchors already marked up with unique classes, or they all happen to be able to be targeted through the DOM then you really won't be saving any time vs simply going through and adding target manually.

Keep in mind some people do get annoyed with new windows opening up.
racer x is offline
Reply With Quote
View Public Profile Visit racer x's homepage!
 
Old 05-09-2009, 08:32 PM Re: What is the PHP way of saying this?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
No need for jQuery though:
JavaScript:
PHP Code:
<!--end of any page-->
<
script type="text/javascript">
var 
document.getElementsByTagName("a");
for (var 
node in a) {
   if(
a[node].href == "http://my-website.com/my-page-for-new-page.php")
      
a[node].target "_blank";
}
</script> 
Pretty simple, huh?
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 05-10-2009, 12:02 AM Re: What is the PHP way of saying this?
Super Talker

Posts: 101
Trades: 0
Thanks guys and thanks wayfarer07 for the javascript. I asked the same question in yahoo answers and people there said the same thing, that php doesn't handle this sort of thing. I ended up doing a search and replace and solved the issue, but I will keep the JS in my collection in case I need it in the future.

Thanks again.
Towhid is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to What is the PHP way of saying this?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21246 seconds with 12 queries