Jump to content

display javascrpt dependng on specific domain?


toolman

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!

Link to comment
Share on other sites

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);
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.