title: Google Maps Places API: "Failed to execute 'write' on doc" error
body: <p>I'm trying to load the Google Maps places API so that I can add autocomplete to my search box. I tried originally pasted the script tags write on the page, but I got the error "Execute write on doc: It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened." I looked up the error and a lot of sources said that I need to load the script in window.onload, so I tried doing that but I'm still getting the "Execute write on doc" error.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      var acService; 
  
      function loadScript() {
          debugger;
          var script = document.createElement('script');
          script.type = 'text/javascript';
          script.src = 'http://maps.google.com/maps/api/js?v=3&amp;libraries=places!callback';
          document.body.appendChild(script);
          acService = new google.maps.places.AutocompleteService(),
              placesService = new google.maps.places.PlacesService(document.createElement('div'));
  
          $("input#location").autocomplete({
              source: function(req, resp) {
  
                  acService.getPlacePredictions({
                      input: req.term,
                      types:['(regions)']
                  }, function(places, status) {
                      if (status === google.maps.places.PlacesServiceStatus.OK) {
                          var _places = [];
                          for (var i = 0; i &lt; places.length; ++i) {
                              _places.push({
                                  id: places[i].place_id,
                                  value: places[i].description,
                                  label: places[i].description
                              });
                          }
                          resp(_places);
                      }
                  });
              },
              select: function(e, o) {
                  placesService.getDetails({
                      placeId: o.item.id
                  }, function(place, status) {
                      if (status === google.maps.places.PlacesServiceStatus.OK) {
                          alert(o.item.value +
                              '\n is located at \n ' +
                              place.geometry.location.toUrlValue());
                      }
                  });
  
  
              }
          });
      }
  
      window.onload = loadScript;
  &lt;/script&gt;
  </code></pre>
  
  <p>This was the first thing I tried with the same error:</p>
  
  <pre><code>&lt;script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&amp;libraries=places"&gt;&lt;/script&gt;
  &lt;input id="location" /&gt;
  
  &lt;script type="text/javascript"&gt;
      function bindAutocomplete() {
  
          var acService = new google.maps.places.AutocompleteService(),
            placesService = new google.maps.places.PlacesService(document.createElement('div'));
  
          $("input#location").autocomplete({
              source: function(req, resp) {
  
                  acService.getPlacePredictions({
                      input: req.term,
                      types:['(regions)']
                  }, function(places, status) {
                      if (status === google.maps.places.PlacesServiceStatus.OK) {
                          var _places = [];
                          for (var i = 0; i &lt; places.length; ++i) {
                              _places.push({
                                  id: places[i].place_id,
                                  value: places[i].description,
                                  label: places[i].description
                              });
                          }
                          resp(_places);
                      }
                  });
              },
              select: function(e, o) {
                  placesService.getDetails({
                      placeId: o.item.id
                  }, function(place, status) {
                      if (status === google.maps.places.PlacesServiceStatus.OK) {
                          alert(o.item.value +
                            '\n is located at \n ' +
                            place.geometry.location.toUrlValue());
                      }
                  });
  
  
              }
          });
      }
      $(window).load(bindAutocomplete);
  &lt;/script&gt;
  </code></pre>