using javscript to replace the src of an embeded google map

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

using javscript to replace the src of an embeded google map

Post by anthony88guy »

This is what my embeded google maps code looks like:

Code: Select all

<iframe id="googleMap" width="476" height="345" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&view=map&q=shoreham+verizon+wireless&sll=40.946977,-72.89445&sspn=0.038444,0.090981&gl=us&ie=UTF8&cid=15856891361931225563&ll=40.952029,-72.884502&spn=0.018475,0.036821&z=14&iwloc=A&output=embed"></iframe>
I would like to make a link so that when you click on it, it updates the src in the iframe above. Thus changing the map.

Here is what I have:

Code: Select all

<script type="application/javascript">
function switchDirection(newSrc)
{
    document.getElementById("googleMap").src=newScr;
}
</script>

Code: Select all

<a href="javascript&#058;switchDirection('http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=rocky+point,+ny+to+99+route+25a,+11786&sll=40.941095,-72.920705&sspn=0.023146,0.06609&ie=UTF8&ll=40.941106,-72.92038&spn=0.022692,0.036478&z=14&output=embed');">Rocky Point</a>
Could some please point me in the correct direction.
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: using javscript to replace the src of an embeded google map

Post by mikemike »

Code: Select all

document.getElementById("googleMap").src=newScr;
Should be:

Code: Select all

document.getElementById("googleMap").location=newScr;
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Re: using javscript to replace the src of an embeded google map

Post by anthony88guy »

Why would you set the location property to the "newSrc"? There is no location property... anyway it didn't work.
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: using javscript to replace the src of an embeded google map

Post by mikemike »

That's what a simple Google search gave me, I tried it in the w3schools editor and it worked fine
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Re: using javscript to replace the src of an embeded google map

Post by anthony88guy »

hmm, ill take a look. What did you search for?
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Re: using javscript to replace the src of an embeded google map

Post by anthony88guy »

Code: Select all

document.getElementById("googleMap").setAttribute("src",newSrc)
is what was needed.

thanks
Post Reply