Solved

Tracking URLs

Posted on 2002-06-06
13
179 Views
Last Modified: 2010-04-09
Hi,

If I have the URL www.mysite.com/index.htm?track how do I get the ?track to pass on to any other webpage on my website as someone follows links?

I remember seeing a very simple solution about 2 years or so ago but I don't remember what it is.

Thanks,
Tim
0
Comment
Question by:timshank
  • 6
  • 4
  • 2
  • +1
13 Comments
 
LVL 30

Expert Comment

by:third
ID: 7061224
<script>
  var param = window.location.href.substring(window.location.href.indexOf('?'));
</script>
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7061711
Some shorter, pts to third:

<script>
 var param = window.location.href.substring(1);
</script>
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7061712
:-/ that is wrong

var param = location.search.substring(1);
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:timshank
ID: 7062223
I've tried all 3 of the suggestions and they don't seem to be working, perhaps I explained it wrong.

If someone is on my site on page mysite.com/page.htm?track and clicks on a link to my faq.htm page I want the URL to be mysite.com/faq.htm?track

The substring ( I think that is what it's called, it's the part of the URL after the question mark ) will change, depending on where the person enters my site from.

I tried these suggestions in the head section and also in the body of the page but it isn't passing the ?track on to the next page.

Thanks!
Tim
0
 
LVL 18

Expert Comment

by:bruno
ID: 7062545
can you use ASP?

if you had to actually modify the links, is it worth it?

ie:

change your links from..

faq.html

to

faq.html?<%=qString%>


I can give you code that will grab it in ASP, but you'll have to modify your links as I showed...



BRUNO
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7062727
Add the following code to all your pages:

<script language="javascript">
<!--
var sSearch = location.search.substring(1);
function document_onload()
{
   for(i=0;i<document.links.length;i++) document.links[i].href+="?"+sSearch;
}
window.onload=document_onload;
//-->
</script>
0
 

Author Comment

by:timshank
ID: 7063733
That almost works. The problem is that if someone comes to my site through a search engine, or if they type in my domain and then as they travel through the pages the script will add a ? to the end of my URL. Is there a workaround for this?

Thanks,
Tim
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7064132
<script language="javascript">
<!--
var sSearch = (location.search.length>0?"?"+location.search.substring(1):"";
function document_onload()
{
  for(i=0;i<document.links.length;i++) document.links[i].href+=sSearch;
}
window.onload=document_onload;
//-->
</script>
0
 

Author Comment

by:timshank
ID: 7064271
Hi,

I get a error that says it needs a ). I added one on line 3 of the script like this

<script language="javascript">
<!--
var sSearch = (location.search.length>0?"?"+location.search.substring(1):"");
function document_onload()
{
 for(i=0;i<document.links.length;i++) document.links[i].href+=sSearch;
}
window.onload=document_onload;
//-->
</script>

This seems to work. I just wanted to make sure before I added it to all my pages.

Thanks,
Tim
0
 
LVL 22

Accepted Solution

by:
CJ_S earned 50 total points
ID: 7064274
Yea, I forgot that one :-)

CJ
0
 
LVL 18

Expert Comment

by:bruno
ID: 7064364
ohhh CJ you're lucky when I saw the "proposed" notif I was gonna get mad...


:-)
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7064370
;-) I know what I do :-)
0
 

Author Comment

by:timshank
ID: 7064379
Thank you. Cool script.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Form with Modals 16 55
coldfusion grab more the one form field to make an insert 3 40
help squeezing some space out in this site 9 31
Joomla 2.5 shopping cart 7 23
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now