Jump to content

Recommended Posts

Hi there,

 

I am trying to display some javascript depending on specific domains. For example, I have several websites using the scame script, such as www.mydomain.com/website1, www.mydomain.com/website2, www.mydomain.com/website3, www.mydomain.com/website4 etc.They all use the same files.

 

Is there a way I can use an if statement to display the javascript on say just /website2 and /website3 ?

 

Many thanks!

Personally I would add this check within the PHP script, instead of using Javascript to conditionally include Javascript. However you could do it with:

 

if (/^\/website1/.match(location.path)
 || /^\/website2/.match(location.path)) {
    var script = document.createElement('script');
    script.src = '/this/extra/script.js';
    document.head.appendChild(script);
}

Does this by chance have to do with a tracking script such as Google Analytics or Omniture SiteCatalyst? I only ask because whenever I see a question like this, it is almost always about tracking code, and making it not pop on dev/qa sites. If by chance this is what it is about, you should know that most tracking tools have solutions for dealing with this. I can go into more detail if that is what this is about.

Hi,

 

Yes this is to do with tracking, but the websites all use the same script/files, so it will track all websites rather than just specific ones. It's not Google or Omniture SiteCatalyst, it's an independant tracking script.

 

Any ideas for a work around?

Okay well I can't give you any specific insight without knowledge of the tracking script.  But are you looking to suppress the code from executing and reporting data, or are you looking to have the data routed to a different "account"? 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.