javascript - dynamic variables in an iframe -
i trying use html5 geocoding pass dynamic lat , long iframe. far can get. can't quite lat , lon work iframe src.
how pass variables iframe properly?
<!doctype html> <html> <body> <script type="text/javascript"> function mylat(position) { text(position.coords.latitude); } function mylon(position) { text(position.coords.longitude); } document.write('<iframe id="forecast_embed" type="text/html" frameborder="0" height="245" width="100%" src="http://forecast.io/embed/#lat='+mylat+'&lon='+mylon+'&name=your location"> </iframe>'); </script> </body> </html>
have looked @ documentation geolocation? following want:
navigator.geolocation.getcurrentposition(function(position) { var lat = position.coords.latitude; var lon = position.coords.longitude; document.write('<iframe id="forecast_embed" type="text/html" frameborder="0" height="245" width="100%"' + 'src="http://forecast.io/embed/#lat=' + lat + '&lon=' + lon + '&name=your location"> </iframe>'); });
Comments
Post a Comment