Solved

Tracking URLs

Posted on 2002-06-06
13
180 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

840 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