Solved

Tracking URLs

Posted on 2002-06-06
13
172 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
Comment Utility
<script>
  var param = window.location.href.substring(window.location.href.indexOf('?'));
</script>
0
 
LVL 22

Expert Comment

by:CJ_S
Comment Utility
Some shorter, pts to third:

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

Expert Comment

by:CJ_S
Comment Utility
:-/ that is wrong

var param = location.search.substring(1);
0
 

Author Comment

by:timshank
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:timshank
Comment Utility
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
Comment Utility
<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
Comment Utility
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
Comment Utility
Yea, I forgot that one :-)

CJ
0
 
LVL 18

Expert Comment

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


:-)
0
 
LVL 22

Expert Comment

by:CJ_S
Comment Utility
;-) I know what I do :-)
0
 

Author Comment

by:timshank
Comment Utility
Thank you. Cool script.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
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…

763 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

11 Experts available now in Live!

Get 1:1 Help Now