0

How can I listen for these events at the same time? (Currently not working)

<!DOCTYPE html>
<html>
  <head>
    <title>Cordova Device Ready Example</title>
    <script type="text/javascript" charset="utf-8" src="cordova-2.7.0.js"></script>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script>
    <script type="text/javascript" charset="utf-8">

        function onLoad() {
            document.addEventListener("deviceready", onDeviceReady, false);
        }

        function onDeviceReady() {
            loadMap();
        }

        function loadMap() {
            var map, layer;

            function initialize() {
              var chicago = new google.maps.LatLng(41.850033, -87.6500523);

              map = new google.maps.Map(document.getElementById('map-canvas'), {
                center: chicago,
                zoom: 11,
                mapTypeId: google.maps.MapTypeId.ROADMAP
              });

              layer = new google.maps.FusionTablesLayer({
                query: {
                  select: '\'Geocodable address\'',
                  from: '1mZ53Z70NsChnBMm-qEYmSDOvLXgrreLTkQUvvg'
                }
              });
              layer.setMap(map);
            }

            google.maps.event.addDomListener(window, 'load', initialize);
        }

    </script>
  </head>
  <body onload="onLoad()">
    <div id="map-canvas"></div>
  </body>
</html>
jskidd3
  • 4,609
  • 15
  • 63
  • 127

1 Answers1

2

remove "onLoad" from body tag and add it like this in the script:-

window.addEventListener("load", onLoad);

This way you can listen to multiple events added on the load event.

You can look at this for better understanding

element.onload vs element.addEventListener("load",callbak,false)

Community
  • 1
  • 1
pvnarula
  • 2,771
  • 18
  • 22