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

  • SEARCH
  • Home
  • 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 1107267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:54:47+00:00 2026-05-17T01:54:47+00:00

I have been trying forever but it is just not working, how can I

  • 0

I have been trying forever but it is just not working, how can I check the array of urls I got (document.getElementsByTagName('a').href;) to see if any of the websites are in another array?

  • 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-17T01:54:48+00:00Added an answer on May 17, 2026 at 1:54 am
    var linkcheck = (function(){
      if(!Array.indexOf){
        Array.prototype.indexOf = function(obj){
      for(var i=0; i<this.length; i++){
        if(this[i]===obj){
          return i;
        }
      }
          return -1;
        }
      }
      var url_pages = [], anchor_nodes = []; // this is where you put the resulting urls
      var anchors = document.links; // your anchor collection
      var i = anchors.length;
      while (i--){
        var a = anchors[i];
        anchor_nodes.push(a); // push the node object in case that needs to change
        url_pages.push(a.href); // push the href attribute to the array of hrefs
      }
      return {
        urlsOnPage: url_pages, 
        anchorTags: anchor_nodes, 
        checkDuplicateUrls: function(url_list){
          var duplicates = []; // instantiate a blank array
          var j = url_list.length;
          while(j--){
            var x = url_list[j];
            if (url_pages.indexOf(x) > -1){ // check the index of each item in the array.
              duplicates.push(x); // add it to the list of duplicate urls
            }
          }
          return duplicates; // return the list of duplicates.
        },
        getAnchorsForUrl: function(url){
          return anchor_nodes[url_pages.indexOf(url)];
        }
      }
    })()
    // to use it:
    var result = linkcheck.checkDuplicateUrls(your_array_of_urls);
    

    This is a fairly straight forward implementation of a pure JavaScript method for achieving what I believe the spec calls for. This also uses closures to give you access to the result set at any time, in case your list of urls changes over time and the new list needs to be checked. I also added the resulting anchor tags as an array, since we are iterating them anyway, so you can change their properties on the fly. And since it might be useful to have there is a convenience method for getting the anchor tag by passing the url (first one in the result set). Per the comments below, included snippet to create indexOf for IE8 and switched document.getElementsByTagName to document.links to get dynamic list of objects.

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

Sidebar

Related Questions

I'm not sure what I'm doing wrong, but I have been trying forever to
I have been trying for a while now, but I can't figure out how
I have been trying to create a ListView which I can sort using drag
I have been working on this for what seems like forever, so I finally
Have been trying to write an awk script which processes a log file, but
Have been trying to get a fresh, just created rails application to work on
I have been trying to find a solution for past few hours but unable
Have been trying to encrypt an xml file to a string so that I
Have have been trying to make a validator for my xml files. I have
I have been trying to setup git for our web development team unsuccessfully. Some

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.