By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,256 Members | 1,700 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,256 IT Pros & Developers. It's quick & easy.

Script only works in one URL

P: 6
I am trying to write a scriupt to serve ad slot for each region. URL's are generated dynamically. OK, so I have the following code to display the ad (Google Ad Manager)

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript"> 
  2. if (location.href.substring(75,76) == "1")
  3. {
  4. GA_googleFillSlot("Button4");
  5. }
  6. </script>
The script works fine as long as the page is served from http://www.atlanticportal.com

The Problem is that the script wont work with any of the other URL's that I have such as Http://atlanticportal.com or http://www.atlanmticportal.ca

How can I fix this?
reply
Feb 24 '10 #1
Share this Question
Share on Google+
9 Replies


gits
Expert Mod 5K+
P: 5,390
what should be really checked in your line 2?

kind regards
Feb 24 '10 #2

P: 6
I am trying to have change the ads based on the Region. For Example: If region = 1 show ad slot 6.

If you look at the following URL the ads show up at the left hand menu column. http://www.atlanticportal.com/Atlant...onName=Western
but they dont show up in the following url
http://www.atlanticportal.ca/Atlanti...onName=Western

The only difference in the url's is one is .com and the other is .ca
Feb 24 '10 #3

gits
Expert Mod 5K+
P: 5,390
as you might see that is the problem ... your substring method relies on the position of the character you want to check ... so it doesn't match when anything is changed before ... like the domain name.

i would suggest to use a regExp ... like this:

Expand|Select|Wrap|Line Numbers
  1. if (/region=1/ig.test(location.href)) {
  2.     alert('match region 1');
  3. }
kind regards
Feb 25 '10 #4

P: 6
OK so I have the following code and it works for each URL, however, it seems rather cumbersome. Is there a way to simplify this by using a relative path perhaps?

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     if (document.location.href.substr(74,75,76) == "1" || location.href == "http://www.atlanticportal.com/AtlanticPortal/en/WhereToStay.aspx?Region=1&Community=0&Category=1&ProvID=1&RegionName=Western" || location.href == 
  3.  
  4. "http://www.atlanticportal.ca/AtlanticPortal/en/WhereToStay.aspx?Region=1&Community=0&Category=1&ProvID=1&RegionName=Western" || location.href == 
  5.  
  6. "http://atlanticportal.ca/AtlanticPortal/en/WhereToStay.aspx?Region=1&Community=0&Category=1&ProvID=1&RegionName=Western" || location.href == 
  7.  
  8. "http://atlanticportal.com/AtlanticPortal/en/WhereToStay.aspx?Region=1&Community=0&Category=1&ProvID=1&RegionName=Western")
  9.         {   
  10.         GA_googleFillSlot("Button4");}
  11. </script>
Feb 25 '10 #5

gits
Expert Mod 5K+
P: 5,390
huhh? ... why don't you use the regExp condition i showed you above? :) ...
Feb 25 '10 #6

P: 6
I tried it but it didnt work...
Feb 25 '10 #7

gits
Expert Mod 5K+
P: 5,390
please show what you have tried ... the regExp should always match when region=1 is contained by the string that is tested ...
Feb 25 '10 #8

P: 6
First off, I have to say a big thank you for you taking the time to help me out! I really appreciate it. Good Karma for you!

I used the code as you posted it, but when I used your code, I got a pop up asking me to confirm that region =1. Once clicked to confirm, the page displayed properly.
Feb 25 '10 #9

gits
Expert Mod 5K+
P: 5,390
remove the alert() ... i just showed it as an example ...
Feb 26 '10 #10

Post your reply

Sign in to post your reply or Sign up for a free account.