Using document.write after the DOM is finished destroys the document.
To dynamically add the script, you need to insert a script element.
Here's an example: 
http://blogs.missouristate.edu/web/2010/05/12/google-maps-api-v3-developing-for-mobile-devices/

In the above article the API is loaded during the DOMContentLoaded
event. You can substitute any trigger you wish.

Chad Killingsworth

On Nov 8, 10:56 am, Derek Winkler <winkl...@gmail.com> wrote:
> I'm trying to dynamically load the API only when the user needs it
> (through a document.write, essentially). However, when it writes the
> script element, the page reloads to a blank page. Logging the head
> element to Firebug shows me this:
>
> <script
> src="http://maps.google.com/maps?file=api&v=3&sensor=false&key...";
> type="text/javascript" id="ext-gen234">
> Failed to load source 
> for:http://maps.google.com/maps?file=api&v=3&sensor=false&key=ABQIAAAA_Vw...
> </script>
>
> I'm able to load other JS files via this method with no problems,
> granted they are all locally hosted. If the script tag is present at
> page load, everything seems to work as expected.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to google-maps-js-api...@googlegroups.com.
To unsubscribe from this group, send email to 
google-maps-js-api-v3+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to