toolman Posted January 21, 2013 Share Posted January 21, 2013 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! Quote Link to comment https://forums.phpfreaks.com/topic/273427-display-javascrpt-dependng-on-specific-domain/ Share on other sites More sharing options...
Adam Posted January 22, 2013 Share Posted January 22, 2013 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); } Quote Link to comment https://forums.phpfreaks.com/topic/273427-display-javascrpt-dependng-on-specific-domain/#findComment-1407463 Share on other sites More sharing options...
.josh Posted January 22, 2013 Share Posted January 22, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/273427-display-javascrpt-dependng-on-specific-domain/#findComment-1407534 Share on other sites More sharing options...
toolman Posted January 23, 2013 Author Share Posted January 23, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/273427-display-javascrpt-dependng-on-specific-domain/#findComment-1407752 Share on other sites More sharing options...
.josh Posted January 23, 2013 Share Posted January 23, 2013 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"? Quote Link to comment https://forums.phpfreaks.com/topic/273427-display-javascrpt-dependng-on-specific-domain/#findComment-1407801 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.