using evalJS on Andriod

You must Login before you can answer or comment on any questions.

TestMap2 :
 
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map_canvas { height: 100% }
    </style>
    <script type="text/javascript"
      src="http://maps.googleapis.com/maps/api/js?key=AIzaSyC4ytTVbPw0njniqEALKQUkK3TWjlyeyVA&sensor=false">
    </script>
    <script type="text/javascript">
      function initialize() {
        var mapOptions = {
          center: new google.maps.LatLng(-34.397, 150.644),
          zoom: 8,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"),
            mapOptions);
      }
 
      function changeMarker() {
        alert('hi');
      }
    </script>
  </head>
  <body onload="initialize()">
    <div id="map_canvas" style="width:100%; height:100%"></div>
  </body>
</html>
 
Now I call this to create a Web View:
 
var css = central_object.getContent('TestMap2');
 
        map_content = Ti.UI.createWebView({
            top : 0,
            left : 0,
            color : "#2D2D2D",
            font : {
                fontSize : 14,
                fontFamily : 'Arial'
            },
            html : css,
            width : 'auto',
            scalesPageToFit : true,
            setZoomScale : 2.0
        });
 
        map_content.evalJS("changeMarker();");
The problem I am seeing is that the alert is not called? Is their any reason why this code would not work?

2 Answers

You need to wait for the webview to load. Try to eval the code after the load event triggers. And also the webview won't do anything until you add it to the parent view/window.

— answered 9 months ago by Dan Tamas
answer permalink
2 Comments
  • mmm, this means to keep the post open and start doing something else, Aaron will answer first :D

    — commented 9 months ago by Dan Tamas

  • LOL

    — commented 9 months ago by Aaron Saunders

Your Answer

Think you can help? Login to answer this question!