Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

Tracking URLs

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
timshank
Asked:
timshank
  • 6
  • 4
  • 2
  • +1
1 Solution
 
thirdCommented:
<script>
  var param = window.location.href.substring(window.location.href.indexOf('?'));
</script>
0
 
CJ_SCommented:
Some shorter, pts to third:

<script>
 var param = window.location.href.substring(1);
</script>
0
 
CJ_SCommented:
:-/ that is wrong

var param = location.search.substring(1);
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
timshankAuthor Commented:
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
 
brunoCommented:
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
 
CJ_SCommented:
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
 
timshankAuthor Commented:
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
 
CJ_SCommented:
<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
 
timshankAuthor Commented:
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
 
CJ_SCommented:
Yea, I forgot that one :-)

CJ
0
 
brunoCommented:
ohhh CJ you're lucky when I saw the "proposed" notif I was gonna get mad...


:-)
0
 
CJ_SCommented:
;-) I know what I do :-)
0
 
timshankAuthor Commented:
Thank you. Cool script.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now