Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6605787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:19:32+00:00 2026-05-25T19:19:32+00:00

I have 2 index pages with approx. 150 links on each. I would rather

  • 0

I have 2 index pages with approx. 150 links on each. I would rather maintain 1 page and just generate the links dynamically based on a variable value. For example create a list of links. link1, link2, link3… and based on a variable value being ‘true’ replace those links with list of alternate links i.e. altlink1, altlink2, altlink3…

I have figured out how to do this once but rather than writing the same code over and over for each link I was wondering if there was a faster way. Like creating a list “a” and corresponding list “b” or something like that. I have included my current code below and I look forward to your advice.

<script type="text/javascript">          
// link rewriter        
var hostadd = location.host;
var vendor = '999.99.999.99';
var localaccess = 'somesite.com';

    $(document).ready (
    function link_switcher(){ 
    //if not a vendor route to alternate website
    if (hostadd != vendor) { $("a[href= 'https://www.somelink1.com']").attr    ('href', 'https://www.alternatelink1.com')  }
});
</script>

is it possible to create an array and then javascript that would say replace link1 in array a with alternatelink1 in array b?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:19:33+00:00Added an answer on May 25, 2026 at 7:19 pm

    It’s still not entirely clear what you’re trying to do, but if you want to rewrite all links based on a lookup table that tells you what link to convert to what, here’s how you could do that:

    // Table of links. 
    // Key is original page source URL
    // Data is link to change it to
    var linkData = {
        "http://www.google.com": "http://www.bing.com/",
        "http://mail.google.com/mail/?shva=1#inbox": "http://www.hotmail.com"    
    };
    
    // find every link in the page and change it if it's value is found in the linkData table
    $("a").each(function() {
        var link = this.getAttribute("href");  // use getAttribute to get what was actually in the page, perhaps not fully qualified
        if (linkData[link]) {
            this.href = linkData[link];
        }
    });
    

    If the link is not found in the table, it will not be modified. If there was some pattern to the modification, it might be possible to code that pattern and not have to list every link in the table, but you haven’t shared any info about a pattern.

    And, a working jsFiddle example: http://jsfiddle.net/jfriend00/Cvj8C/.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application with associations and will pagination the pages. The index page
I have an index page with three links as follws. When I click the
I have my index.php page and just afrer my header i want to include
I have pages like index.php?key=toplist&list=magic So if om on that page for example, i
I have two pages: index.html and main.html When i set the main.html page to
So I have 4 pages. They are very simple. index.php (WORKS) <html> <form action=upload.php
I have my index page which posts a single entry instead of the usual
I have an index page index.php , and when the user clicks on a
At current i have an index page which shows values from an XML page
I have a directory on my webserver. It does not have an index page.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.