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
Accepted Answer
map_content.addEventListener('load', function() { map_content.evalJS("changeMarker();"); });
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.
Your Answer
Think you can help? Login to answer this question!