Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Tracking URLs

Posted on 2002-06-06
13
Medium Priority
?
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

715 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