Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Conditional Link URL - Easy Question

Posted on 2016-09-27
4
Medium Priority
?
88 Views
Last Modified: 2016-10-12
Take a look at the following script.
A small block of links that will apear on various different pages.

The logic should be fairly simple to follow.

I need the link target addresses to vary according to the page or content that contains these links.

This might be based on URL?
It could also be based on some identifier or class contained in the surrounding content

Simpler the better - i.e, cSS. Javascrip if necessary.

Any suggestions ?


<table  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><a href=" if current page = A, then link = B "><a href=" if current page = C, then link = D ">Text 1</a></a></td>
    <td><a href=" if current page = E, then link = F "><a href=" if current page = G, then link = H ">Text 2</a></a></td>
    <td><a href=" if current page = I, then link = J "><a href=" if current page = K, then link = L ">Text 2</a></a></td>
  </tr>
</table>
0
Comment
Question by:arthur_raft2
  • 2
4 Comments
 
LVL 30

Expert Comment

by:Dr. Klahn
ID: 41819195
In Apache, nginx, or IIS?
0
 
LVL 44

Accepted Solution

by:
zephyr_hex (Megan) earned 2000 total points (awarded by participants)
ID: 41819917
Here is an example using jQuery

Fiddle Demo here

Given the following HTML:
<table id="myTable" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><a href="">Text 1</a></td>
  </tr>
</table>
<div id="myBtns">
  <input type="button" value="Page A">
  <input type="button" value="Page B">
  <input type="button" value="Page A">
</div>

Open in new window


jQuery
$('#myBtns input').click(function() {
  var newHref = "";
  switch ($(this).val()) {
    case "Page A":
      newHref = "Link 1"
      break;
    case "Page B":
      newHref = "Link 2"
      break;
    case "Page C":
      newHref = "Link 3"
      break;
  }
  $('#myTable a').attr('href',newHref);
  $('#myTable a').text(newHref);
});

Open in new window

0
 
LVL 44

Expert Comment

by:zephyr_hex (Megan)
ID: 41834495
Did this answer your question?
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

971 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