473,769 Members | 4,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="doTrac ker('example.co m');">
Visit this Site
</a>

<a href="mailto:so *****@example.c om"
onclick="doTrac ker('so*****@ex ample.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 1982
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="doTrac ker('example.co m');">
Visit this Site
</a>

<a href="mailto:so *****@example.c om"
onclick="doTrac ker('so*****@ex ample.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(th is.href)"

function hitTheServer(pa rameter){
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.javas cript 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(th is.href)"

function hitTheServer(pa rameter){
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.javas cript:
How do I run a server side Script?
<URL: http://jibbering.com/faq/index.html#FAQ4 _34>

onclick="return hitTheServer(th is.href)"

function hitTheServer(pa rameter){
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(t his.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="doTrac ker(this);">
Visit this Site
</a>

<a href="mailto:so *****@example.c om"
onclick="doTrac ker(this);">
Email someone
</a>
function doTracker(what) {
self.location=' tracking.php?li nk='+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.javas cript:
>How do I run a server side Script?
<URL: http://jibbering.com/faq/index.html#FAQ4 _34>

onclick="retur n hitTheServer(th is.href)"

function hitTheServer(pa rameter){
var dummyImage = new Image();
dummyImage.s rc = "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.javas cript 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.javas cript:
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?li nk='+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 - encodeURICompon ent -. (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
3217
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 page (ie. Response.Redirect("xxx.htm")) I want to open the page in another window. Sounds pretty basic, but ..... If you can help, I'd sure appreciate it.
7
7031
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" onclick="window.open(url,null,'resizable=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,width=600,height=400');">Link</a> The page I am opening is not mine. I want to edit the content of the page I am opening, adding text "This page is opened in a new window" as a first thing...
7
2154
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 HREF="javascript:window.open('email_me.htm','','scrollbars=0,menubar=0,heigh t=260,width=400,toolbar=0');" ONMOUSEOVER="changeImagesX('EmailMe_Layer_1', 'images/EmailMe_Layer-1-over.gif'); return true;" ONMOUSEOUT="changeImagesX('EmailMe_Layer_1', 'images/EmailMe_Layer-1.gif'); return true;">
3
3807
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 only if the browser that index.jsp is opened in is NOT maximized. If index.jsp is maximized and then I click on the test link that fires off the openMain function, the browser that is opened for the popup is also maximized. function...
1
1178
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 open in a new window and have an address that is my page name (modelinfo.aspx). That part is easy, as this is built into the datagrid control. But the last thing I need is a varible on it, so when the hyperlink is clicked, a New page would open and have...
3
1817
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 clicked. At the bottom line i am planning to track(count) all the links <a href-""> how many times each one is clicked. My guess is javascript and cookies
8
1549
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 them that would have code that would visit another site that has a database to keep track of hits and duration of stay at a particular page. I was wondering if it is possible to visit a site in the background so
0
1775
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 tracking number of the current request is imported to the pend form, and query results are displayed at the bottom(all previous pending records for the imported tracking number) the pend button saves either the start pending date or the end pending...
0
9424
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10223
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10051
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9866
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.