I would like to dynamically create a "google maps" link in javascript and than set it as src for my iframe, but I don't know if it is not possible with google maps, because this doesn't work:
document.getElementById('map_canvas').src='http://maps.google.com/maps/ms?ie=UTF8&msa=0&msid=209246852521822593612.0004feda304ac527ea40a&output=embed';
although, for example this works:
document.getElementById('map_canvas').src='http://www.cnn.com';
This is my iframe:
<iframe id="map_canvas" name="map_canvas" width="100%" height="600px"
frameborder="0" scrolling="no" marginheight="0" marginwidth="0"
src="">
</iframe>
Could you explain me, how is it possible to dynamically generate and display a google maps link in iframe ?
Thank you for help!
Use the google maps embed api to embed within an iframe. You are on the right track, you just need a slightly different URL structure for your src.
Where:
Source: https://developers.google.com/maps/documentation/embed/guide
Google want you to access their maps in set ways.
If it's a classic map you want to embed on your website, go here and follow these simple instructions to get an embed code.
Or if you require more control try the Google Maps Javascript API 3. You can sign up for it for free, and use their tutorial and sample code to get it set up.
Solution without iframe:
In your javascript file add the following:
On demand use:
I solved it this way: I have added iframe per jQuery and set the desired src attr.