Google Answers Logo
View Question
 
Q: Javascript for montoring internal links in web page ( No Answer,   7 Comments )
Question  
Subject: Javascript for montoring internal links in web page
Category: Computers > Programming
Asked by: jpalme-ga
List Price: $20.00
Posted: 13 May 2003 04:14 PDT
Expires: 12 Jun 2003 04:14 PDT
Question ID: 203068
I have a web page which contains a link list with internal links
within the web page, i.e.
<a href="#a1">section 1</a><br>
<a href="#a2">section 2</a>, etc.

I want a short report sent by HTTP to the server when the user
clicks on one of these page-internal links. This should not be
visible to the user, but would enable us to know which links
our users use.

Can this be done in some way, for example with some kind
of short Javascript code connected to the link? Can someone
who knows Javascript well provide such a code for us?

Request for Question Clarification by rhansenne-ga on 13 May 2003 04:49 PDT
Hi,

Could you specify what the structure/format of such a report should be
and what it should contain?

Thanks.

Clarification of Question by jpalme-ga on 19 May 2003 17:11 PDT
Yes, we are satisfied with your answers. The first solution, changing
<a href="#a1">to <a href="http://site.net/page#" did not work, because
the information sent to the server did not include which section the
user had chosen. But the other (webbug) solution works.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Javascript for montoring internal links in web page
From: mplungjan-ga on 13 May 2003 06:18 PDT
 
the absolutely SIMPLEST way would be to add the page url too, e.g.
change
<a href="#a1">section 1</a><br> 
<a href="#a2">section 2</a>, etc. 
to
<a href="thispage.html#a1">section 1</a><br> 
<a href="thispage.html#a2">section 2</a>, etc. 

since the actual link will show in the http server log, ready to be
chewed on by any of the many log file analyzers out there, such as you
will find here
://www.google.com/search?q=log+files+analyzer

the second method which could be used in the head of the page, f.ex.
using an external js file is this:

<script>
function addInfo() {
   document.images.saveInfo.src='testimage.gif?'+this.href
}
function initPage() {
  for (i=0;i<document.links.length;i++) 
    if (document.links[i].href.indexOf('#')!=-1) {
      document.links[i].onclick=addInfo;
    }
  }
}
window.onload=initPage;

Michel
Subject: Re: Javascript for montoring internal links in web page
From: mplungjan-ga on 13 May 2003 06:21 PDT
 
PS: this assumes a gif image somewhere (called a web bug)

<img src="blank.gif" width="1" height="1" name="saveInfo">

and will ALSO show in the http log files as
testimage.gif?urlClickedByUser

This image can ALSO be created by script by using inline script (e.g
at load time NOT after) and
document.write('<img src="blank.gif" width="1" height="1"
name="saveInfo">')
Subject: Re: Javascript for montoring internal links in web page
From: mplungjan-ga on 13 May 2003 06:23 PDT
 
Lastly
document.images.saveInfo.src
can be written
document.images['saveInfo'].src
which I actually prefer :)

Michel
Subject: Re: Javascript for montoring internal links in web page
From: jpalme-ga on 13 May 2003 08:50 PDT
 
Your suggestions sound very good, we will try them out and see
how they work. Thank you!
Subject: Re: Javascript for montoring internal links in web page
From: chrisken-ga on 15 May 2003 01:14 PDT
 
Just a slight modification to mplungjan-ga's answer:
<a href="?#a1">section 1</a><br />
<a href="?#a2">section 2</a>

That way it's independent of the filename.
Subject: Re: Javascript for montoring internal links in web page
From: mplungjan-ga on 15 May 2003 12:50 PDT
 
What do you mean by not dependant of the filename?
The filename is needed unless the section names are unique for all pages...
Subject: Re: Javascript for montoring internal links in web page
From: mplungjan-ga on 15 May 2003 12:51 PDT
 
PS: If you are (almost) happy with the comments let me know what you
need in order for me to post them as answer. My comments were
initially just meant to get you started since I had little time to
follow them up.

Michel

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy