SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    UK
    Posts
    245
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Google maps & Mutiple Domains but one site.

    I have a site that uses 2 domains to forward to the IP no. (a .org.uk and .co.uk). The site uses the Google Map API for a map on the site, however the API key is locked to the individual domain (I do have two keys for both the domains). I found the following Javascript which is supposed to switch the key depending on the domain that is accessing the page.
    Code:
     if (window.location.host == 'www.domain1.com') { 
         document.write('<'+'script 
    src="http://maps.google.com/maps?file=api&v=1&key=key/for/domain1" 
    type="text/javascript">' + 
         '<'+'/script>'); 
       } else if (window.location.host == 'www.domain2.com') { 
         document.write('<'+'script 
    src="http://maps.google.com/maps?file=api&v=1&key=key/for/domain2" 
    type="text/javascript">' + 
         '<'+'/script>'); 
       } else { 
    alert("host ="+window.location.host); 
    }
    but I can't get it to work, the page doesn't display any map (not even an alert) if I use this instead of the normal API key script.

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    could it be that the if statements don't match the web urls?

    what about

    if(location.Url.indexOf('domain1.com')>-1)
    {
    // do your stuff.
    }


  3. #3
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    UK
    Posts
    245
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts
    could it be that the if statements don't match the web urls?

    what about

    if(location.Url.indexOf('domain1.com')>-1)
    {
    // do your stuff.
    }
    Still can't get it to work, doesn't display anything
    http://www.parksideactiongroup.org.u...tive-map3.html

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    firefox javascript console:

    Error: GUnload is not defined
    Source File: http://www.parksideactiongroup.org.u...tive-map3.html
    Line: 1

    Error: unterminated string literal
    Source File: http://www.parksideactiongroup.org.u...tive-map3.html
    Line: 8, Column: 24
    Source Code:
    document.write('<'+'script

    Error: GOverlay is not defined
    Source File: http://www.parksideactiongroup.org.uk/js/einsert.js
    Line: 19

    Error: GBrowserIsCompatible is not defined
    Source File: http://www.parksideactiongroup.org.u...tive-map3.html
    Line: 106

    I'm trying to work out why your doing document.write('<'+'script when you can simply do document.write('<script.

    Gav


  5. #5
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    UK
    Posts
    245
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found the script on Google's support forum, as I am by no means a Javascript expert, and to be honest I don't have much clue about what the most parts of the script do.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •