Fix for iframe calling location.href
I'm trying to embed a mapquest direction page such as http://www.mapquest.com/maps?1c=Ann+Arbor&1s=MI&1a=1440+Hubbard+St&1z=48109-2083&1y=US&1l=42.293437&1g=-83.724491&1v=ADDRESS&2c=Ann+Arbor&2s=MI&2a=930+N+University+Ave&2z=48109-1055&2y=US&2l=42.278558&2g=-83.7开发者_开发知识库37969&2v=ADDRESS using an iframe. The problem is at least one of their javascripts calls location.href which is causing the script to hang. If I'm not mistaken this is because the page I'm embedding the page on is in a different domain. Are there any ways around this?
It seems like you need to use their "embeddable maps" feature instead of iframing it yourself.
Cross-domain DOMing is a no no, and browser makers work hard to make sure you can't violate the same-source policy. This is a major security concern, so it really can't be done.
When I use the "Link to/Embed" option on the site I get this given back to me:
<iframe style="height: 270px; width: 450px;" src="http://www.mapquest.com/embed#b
/maps/m:map:12:42.293449:-83.724489::::::1:1:::::::::
/l::1440+Hubbard+St:Ann+Arbor:MI:48109-2083:US:42.293437:-83.724491:address::1:::
/l::930+N+University+Ave:Ann+Arbor:MI:48109-1055:US:42.278558:-83.737969:address::1:::
/io:1:::::f:en_US:M::/e" marginwidth="0" marginheight="0" frameborder="0" scrolling="no">
</iframe>
So it appears they make their own scripts etc that run within the iframe.
EDIT
Google maps shows the directions on the embedded map, if that's an option for you: Google Maps link
精彩评论