user2597417
user2597417

Reputation: 99

Incorporating google maps api into chrome extension/alternative to document.write

I am trying to incorporate google maps api into my chrome extension. However, I found out that manifest version 2 does not allow document.write. Is there any way around this?

Upvotes: 4

Views: 938

Answers (1)

Michael Geary
Michael Geary

Reputation: 28870

Use the callback URL parameter when you load the Maps API, and it won't use document.write(). In a normal web page you might do it like this:

function initMap() {
    // Create the map object here as usual
}

function loadMapsAPI() {
    var script = document.createElement( 'script' );
    script.src =
        'http://maps.googleapis.com/maps/api/js' +
        '?sensor=false&callback=initMap';
    document.body.appendChild( script );
}

Documentation

Example

I don't know how this would interact with a Chrome extension, but that's how it's done in a regular web page.

Upvotes: 3

Related Questions