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 6738875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:25:13+00:00 2026-05-26T11:25:13+00:00

The following code snippet is needed to capture html links for my site. Although,

  • 0

The following code snippet is needed to capture html links for my site. Although, it seems to work, I wish to have an explanation so that I may improve upon it. Can someone give me a quick summary of what’s happening in this code? I don’t especially understand the while statement that uses this variable ‘link’. What is ‘link’? A dummy variable of some sort like you would use in a dictionary or map iteration? Also, why use document.links[0]?

 if (document.links){
  if (document.links[0]){
   var links = document.links, link, k=0;
   while(link=links[k++]) {
    link.onclick = linkCapture;
   }
  }
 }

function linkCapture() {
  this.parent = this.parentNode;
  eventCapture('Link Click','Page Tag',this.name,this.href);
}
  • 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-26T11:25:13+00:00Added an answer on May 26, 2026 at 11:25 am
     if (document.links){
    

    The browser supports the property:

      if (document.links[0]){
    

    There is at least one link:

       var links = document.links, link, k=0;
    

    Standard initialization

       while(link=links[k++]) {
    

    For every run through the loop, set link to the next element, then increment k. Exit the loop when the current links[k] is falsy (probably because we’ve passed the last element).

        link.onclick = linkCapture;
    

    Set the onclick property to linkCapture.

    This really isn’t great code to begin with. You could write the whole thing using jQuery like:

    $(document.links).click(linkCapture);
    

    As a bonus, you wouldn’t risk overwriting an existing onclick property.

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

Sidebar

Related Questions

I have the following code snippet: using (SPSite site = new SPSite(this.ListAddress)) { using
The following code snippet returns an array of PropertyInfo objects that have a defined
I have the following code snippet. $items['A'] = Test; $items['B'] = Test; $items['C'] =
Say I have the following code snippet in c# static const bool DO_PERFORMANCE_CODE =
I have the following code snippet where some strings are initialized in the if
This following code snippet works fine using jQuery1.2.3, but it doesn’t work with latest
The following code snippet in a Django template (v 1.1) doesn't work. {{ item.vendors.all.0
The following code snippet only returns in grayscale. I have been troubled by this
I came across the following code snippet and needed to predict the output. My
I have the following code snippet. I am compiling using the sun studio 12

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.