javascript - Should I include the Google Map script tag on every page of my website? -


it seems if not include script tag google map on each page of website, error: "uncaught referenceerror: google not defined".

if include script tag on page there no map error "uncaught typeerror: cannot read property 'offsetwidth' of null".

maybe need sort of check system in javascript see if id exists? wasn't sure correct way of incorporating google map api?

this javascript looks like:
// google map

    function initialize() {     var mapcanvas = document.getelementbyid('map-canvas');     var mapoptions = {       center: new google.maps.latlng(44.5403, -78.5463),       zoom: 8,       maptypeid: google.maps.maptypeid.roadmap     }     var map = new google.maps.map(mapcanvas, mapoptions)   }   google.maps.event.adddomlistener(window, 'load', initialize); 

  • include on every page intend use map.

  • don't include elsewhere.

  • fix javascript not things not need done. if don't intend render map, don't write code renders map.


Comments

Popular posts from this blog

c# - ItextSharp font color issue in ver 5.5.4+ -

jquery - Multiple issues with pushstate: history, loading, calling functions -

ios - retrievePeripherals deprecated in IOS7 how to substitude it with retrievePeripheralsWithIdentifiers -