Script only works in one URL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gdicks
    New Member
    • Feb 2010
    • 6

    Script only works in one URL

    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)

    Code:
    <script type="text/javascript"> 
    if (location.href.substring(75,76) == "1")
    {
    GA_googleFillSlot("Button4");
    }
    </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
    Last edited by Dormilich; Feb 24 '10, 12:38 PM. Reason: Please use [code] tags when posting code
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    what should be really checked in your line 2?

    kind regards

    Comment

    • gdicks
      New Member
      • Feb 2010
      • 6

      #3
      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


      The only difference in the url's is one is .com and the other is .ca

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        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:

        Code:
        if (/region=1/ig.test(location.href)) {
            alert('match region 1');
        }
        kind regards

        Comment

        • gdicks
          New Member
          • Feb 2010
          • 6

          #5
          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?

          Code:
          <script type="text/javascript">
          	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 == 
          
          "http://www.atlanticportal.ca/AtlanticPortal/en/WhereToStay.aspx?Region=1&Community=0&Category=1&ProvID=1&RegionName=Western" || location.href == 
          
          "http://atlanticportal.ca/AtlanticPortal/en/WhereToStay.aspx?Region=1&Community=0&Category=1&ProvID=1&RegionName=Western" || location.href == 
          
          "http://atlanticportal.com/AtlanticPortal/en/WhereToStay.aspx?Region=1&Community=0&Category=1&ProvID=1&RegionName=Western")
          		{   
          		GA_googleFillSlot("Button4");}
          </script>

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            huhh? ... why don't you use the regExp condition i showed you above? :) ...

            Comment

            • gdicks
              New Member
              • Feb 2010
              • 6

              #7
              I tried it but it didnt work...

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #8
                please show what you have tried ... the regExp should always match when region=1 is contained by the string that is tested ...

                Comment

                • gdicks
                  New Member
                  • Feb 2010
                  • 6

                  #9
                  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.

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5390

                    #10
                    remove the alert() ... i just showed it as an example ...

                    Comment

                    Working...