I want to append a script tag to the body of my HTML page. I added the following in my page:
The error you are getting is because there is no initialize() function. If you declare one there will be no error.
function loadScript() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize';
document.body.appendChild(script);
console.log('loadScript');
}
function initialize() {
console.log('initialize');
}
window.onload = loadScript;