Conditional "Get Script File" in Javascript without using a library function
Posted
by Adam
on Stack Overflow
See other posts from Stack Overflow
or by Adam
Published on 2010-03-08T20:07:00Z
Indexed on
2010/03/08
20:21 UTC
Read the original article
Hit count: 307
JavaScript
|AJAX
I work at a company that has many clients that have their own website that "plugs in" to our system. In other words they have their own website and they have a link that, when the user clicks it, transitions them over to our site.
There is a feature that I want to track by giving the client a small block of code to put on their homepage. Whenever the homepage is loaded with a certain query string variable I want the block of code to request a file on my server. Then on the server I'll record the tracking info based on the query string.
All this would be really easy if I can guarantee that the client would be using jQuery or some similar library, but there are a lot of clients and I can't really rely on them all using jQuery. At the same time I'd like to limit the size of the block of javascript code that they paste in.
I think the best solution would be to have something like:
if(querystring.substring("Tracking=") > 0)
{
include("blah.aspx?TrackingQS=" + querystring);
}
but I can't find a include
function in built-in javascript without calling some library like jQuery.
Any thoughts?? I could do straight up AJAX but I want to limit the number of lines of code for several reasons that I won't bore you with here.
© Stack Overflow or respective owner