Solved

dynamically change link target property

Posted on 2004-05-02
9
251 Views
Last Modified: 2007-12-19
I have to sites A and B

A has a php with a list of links that is used (included) on both A and B

What i want to achief is:
- clicking on one of those links on site A opens the link in the CURRENT browser window
- clicking on one of those links on site B opens the link in the NEW browser window

Both sites use (different) stylesheets. I was hoping to solve this with the stylesheets and/or javascript and not php.
0
Comment
Question by:bertstevens
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
9 Comments
 
LVL 1

Expert Comment

by:Darix
ID: 10972113
with css you wouldn't solve this, with javascript it is possible, but please, explain why it is not good to use <A href="" target="_self"> and <A href="" target="_blank">. if the same php file is included, you can simply detect from witcha site it was included and depending on that create target attribute.
0
 

Author Comment

by:bertstevens
ID: 10972153
OK, what php line for detection should i then add and what lines to change the target per link?
0
 
LVL 1

Expert Comment

by:Darix
ID: 10972409
it depends how those sites are different. if php script included only from different php file you can detect it with _SERVER["PHP_SELF"] variable, when differs only host name _SERVER["SERVER_NAME"] variable and so on.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:bertstevens
ID: 10972466
they have different urls and servers. I increased point value 75->150  for complete code sample incl changing traget for example link.
0
 
LVL 1

Expert Comment

by:Darix
ID: 10972735
<A href="http://some_server/some_link.php" target="<?php
if (_SERVER["SERVER_NAME"] == "first_server") {
     echo "_blank";
} else {
     echo "_self";
}
?>">Your link</A>


if that was you needed.
0
 

Author Comment

by:bertstevens
ID: 10972811
The would quite ugly with 10 or more links, for the points translate this psuedocode to php:

link[1]="http://server.com/link.php";
text[1]="linktext"

...

link[10]="http://server.com/link.php";
text[10]="linktext"


for i=1 to link.length {

do here the merging and echo of the html

}
0
 
LVL 10

Expert Comment

by:eeBlueShadow
ID: 10974029
You don't even need that.

put this anywhere in your PHP file:

<?php
function getTarget()
{
    if ($_SERVER["SERVER_NAME"] == "your_first_server")
         return "_blank";
    else
         return "_self";
}
?>

then each link looks like

<a href="http://blah.blah.com/" target="<?=getTarget();?>">
0
 
LVL 1

Accepted Solution

by:
Darix earned 150 total points
ID: 10974967
and more better solution:

put this in the top of include file
<?php

    if ($_SERVER["SERVER_NAME"] == "your_first_server")
         $target = "_blank";
    else
         $target = "_self";
?>

then each link looks like:

<a href="http://blah.blah.com/" target="<?=$target;?>">

0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question