473,399 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Open or hit tracking page when link clicked

Hi ...

I have an HTML page containing a bunch of <alinks. Some of the links
redirect the visitor to a page at a different website in a new browser
window (target=_blank) and other links are "mailto" links.

What I want to do is record a little information when they click on a link
(mainly which link they are clicking on). I can put together a server side
webpage that can receive this information and store it in a DB. I'm just
not sure what JavaScript function I would call to "hit" that page. The page
would not be visible. I'm fairly certain AJAX or an iframe would work --
even though I have limited experience with these two techniques. Here's an
example of what I'm looking to do:

<a href="http://www.example.com/"
target="_blank"
onclick="doTracker('example.com');">
Visit this Site
</a>

<a href="mailto:so*****@example.com"
onclick="doTracker('so*****@example.com');">
Email someone
</a>

The doTracker() function would just do two things

1. somehow hit my tracking page (maybe using querystring variables).
2. return true at the end so the link will be executed.

I can pass the information on the link the visitor clicked on via
querystring variables (this seems simplest to do).

My question is, how can I open or hit my tracking page "behind the scenes"?
AJAX, iframe, or something else?

Thanks in advance,
Ben
Mar 11 '07 #1
7 1956
Ben Amada said the following on 3/11/2007 1:44 PM:
Hi ...

I have an HTML page containing a bunch of <alinks. Some of the links
redirect the visitor to a page at a different website in a new browser
window (target=_blank) and other links are "mailto" links.

What I want to do is record a little information when they click on a link
(mainly which link they are clicking on). I can put together a server side
webpage that can receive this information and store it in a DB. I'm just
not sure what JavaScript function I would call to "hit" that page. The page
would not be visible. I'm fairly certain AJAX or an iframe would work --
even though I have limited experience with these two techniques. Here's an
example of what I'm looking to do:

<a href="http://www.example.com/"
target="_blank"
onclick="doTracker('example.com');">
Visit this Site
</a>

<a href="mailto:so*****@example.com"
onclick="doTracker('so*****@example.com');">
Email someone
</a>

The doTracker() function would just do two things

1. somehow hit my tracking page (maybe using querystring variables).
2. return true at the end so the link will be executed.

I can pass the information on the link the visitor clicked on via
querystring variables (this seems simplest to do).

My question is, how can I open or hit my tracking page "behind the scenes"?
AJAX, iframe, or something else?
Something very very trivially simple.

How do I run a server side Script?
<URL: http://jibbering.com/faq/index.html#FAQ4_34>

onclick="return hitTheServer(this.href)"

function hitTheServer(parameter){
var dummyImage = new Image();
dummyImage.src = "scriptURL.php?param=" + parameter;
return true;
}

The server script would then read the param and act on it accordingly.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 11 '07 #2
Randy Webb wrote:
Ben Amada said the following on 3/11/2007 1:44 PM:
>>
My question is, how can I open or hit my tracking page "behind the
scenes"? AJAX, iframe, or something else?

Something very very trivially simple.

How do I run a server side Script?
<URL: http://jibbering.com/faq/index.html#FAQ4_34>

onclick="return hitTheServer(this.href)"

function hitTheServer(parameter){
var dummyImage = new Image();
dummyImage.src = "scriptURL.php?param=" + parameter;
return true;
}

The server script would then read the param and act on it accordingly.
Hi Randy,

I knew it had to be something simple. I'm kicking myself now since I was
just looking something else up in the FAQ prior to posting my question and
didn't even bother to check for something on this topic.

BTW, the "this.href" will definitely make doing this a little easier.

Thank you so much,
Ben
Mar 11 '07 #3
Randy Webb wrote on 11 mrt 2007 in comp.lang.javascript:
How do I run a server side Script?
<URL: http://jibbering.com/faq/index.html#FAQ4_34>

onclick="return hitTheServer(this.href)"

function hitTheServer(parameter){
var dummyImage = new Image();
dummyImage.src = "scriptURL.php?param=" + parameter;
return true;
}
Two Q, since I like compact code:

Is it useful to externalize
var dummyImage = new Image();
using only one new Image() for the whole page?

Do I need the return true?
[not setting return false surely is enough?]

========================================

<script type='text/javascript'>
var dum = new Image();
function doit(x){ dum.src='/doit/?p='+x };
</script>

<a href="http://blah.bla/" onclick="doit(this.href)">
doit</a>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 11 '07 #4
ASM
Ben Amada a écrit :
Hi ...

I have an HTML page containing a bunch of <alinks. Some of the links
redirect the visitor to a page at a different website in a new browser
window (target=_blank) and other links are "mailto" links.

What I want to do is record a little information when they click on a link
(mainly which link they are clicking on). I can put together a server side
webpage that can receive this information and store it in a DB. I'm just
not sure what JavaScript function I would call to "hit" that page.
why not to use server side functions ?

<a href="http://www.example.com/"
target="_blank"
onclick="doTracker(this);">
Visit this Site
</a>

<a href="mailto:so*****@example.com"
onclick="doTracker(this);">
Email someone
</a>
function doTracker(what) {
self.location='tracking.php?link='+encodeURI(what. href);
}

tracking.php
analyzes link clicked (the what href)
then sends back the file already displayed (that's to say itself)

during this time the link does its normal html job
My question is, how can I open or hit my tracking page "behind the scenes"?
AJAX, iframe, or something else?
in same window ... no ?
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Mar 11 '07 #5
Evertjan. said the following on 3/11/2007 4:21 PM:
Randy Webb wrote on 11 mrt 2007 in comp.lang.javascript:
>How do I run a server side Script?
<URL: http://jibbering.com/faq/index.html#FAQ4_34>

onclick="return hitTheServer(this.href)"

function hitTheServer(parameter){
var dummyImage = new Image();
dummyImage.src = "scriptURL.php?param=" + parameter;
return true;
}

Two Q, since I like compact code:

Is it useful to externalize
var dummyImage = new Image();
using only one new Image() for the whole page?
You could, but, the Image() would only get used once per page session as
clicking on the link would change the Image src and then navigate the
browser away from the page. Coming back to the page would cause it to
get created again. And, if the user doesn't use a link you have used an
Image() for nothing. It is 6 of one, half a dozen of the other.
Do I need the return true?
[not setting return false surely is enough?]
You could potentially get in a race condition where the navigation could
occur before the function exited. It would be more fool-proof (not that
it can be 100% fool-proof to start with) if you used the images onload
to return true to allow navigation to continue, thereby ensuring
communication with the server. Communication failure would render that
one useless though.

Right click>Open in new tab/window defeats all of it though.

Truly dependable would be a server app that redirected to the requested URL:

<a
href="http://www.yourServer.com/redirection.php?param=http://www.google.com">
Go to Google
</a>

And then have the server do a redirect after logging the click.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 11 '07 #6
Randy Webb wrote on 11 mrt 2007 in comp.lang.javascript:
Truly dependable would be a server app that redirected to the
requested URL:

<a
href="http://www.yourServer.com/redirection.php?param=http://www.google
.com">
Go to Google
</a>

And then have the server do a redirect after logging the click.
That's whay I am doing for years now, I hoped for a simpler way,
since you have to escape "&" in a second querystring:

href="/redirection.php?param=http://www.google.com/?a=1&b=3">

[this will leave the b=3 at the redirection]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 11 '07 #7
ASM wrote:
<snip>
function doTracker(what) {
self.location='tracking.php?link='+encodeURI(what. href);
}
<snip>

The - encodeURI - would be dangerous to use in this context, as its
subject here is a URL. The appropriate method for use in this context
is - encodeURIComponent -. (See ECMA 262 3rd Ed. Section 15.1.3).

Richard.

Mar 12 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Wes | last post by:
This should be really simple ... but how to do it has been eluding me ... I am writing an ASP.NET application and am using ASP.ImageButtons & ASP.Buttons. Instead of redirecting to another...
7
by: Anna | last post by:
Hi all. I have a (hopefully) pretty simple question. I open a link in a new window: <a href="http://www.somewhere.com/some.hml"...
7
by: Peter Aitken | last post by:
I want to include a button that has rollover effects and also is a link to a page that will open in a new window. Here's the code I am using: <A...
3
by: Bob | last post by:
I am trying to create a popup page (to act as a menu) from a parent page. When the parent page (index.jsp) calls my popup function (see below) it will properly open the correct size browser window...
1
by: Bill | last post by:
I have a datagrid that holds a whole list of records about computers. I need one column that is a hyperlink that when clicked will show the details of that computer model. The hyper link needs to...
3
by: Prince of Code | last post by:
Hey all, I am trying to track the links that are clicked on a particular web page. Like a typical senario will be: Track (Count) how many times the main links Home,Help,About,Login etc are...
8
by: Terry | last post by:
Hi folks. I was thinking about rolling my own anlaytics service for sites that I am working on. I had the idea of using javacript to find all the links on a page and then attach handlers to...
0
by: trixxnixon | last post by:
i have a form that is being designed to pend requests in a requests database. the pend form is opened from an update form used by an employee to enter updates. when the pend form is updated, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.