Including google maps api in chrome extension / alternative document.write

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

+4
source share
1 answer

Use the callback URL parameter when you load the Maps API and it will not use document.write() . On a regular web page, you can do this as follows:

 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 do not know how this will interact with the Chrome extension, but how it is done on a regular web page.

+2
source

Source: https://habr.com/ru/post/1493029/


All Articles