[Google Maps API v3] Prevent link default in InfoWindow on Chrome

70 views
Skip to first unread message

Yo

unread,
Apr 25, 2010, 10:00:21 PM4/25/10
to Google Maps JavaScript API v3
Hi,

I'm experiencing a weird behavior with Chrome and Google Maps API V3.
I'm trying to have a link in an infoWindow that when clicked isn't
redirecting to the target.
This is achieved usually using "onclick='...;return false'".
This code works well on FF and IE, but in Chrome the default is not
prevented.

I've set up a simple example - just copied the code from the official
api tutorial, and added 'onclick="return false"' to the link in the
window:
http://acaspi.com/example/

What should I do to prevent the default in Chrome?

Thanks,
Yo

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

William

unread,
Apr 26, 2010, 8:50:45 AM4/26/10
to Google Maps JavaScript API v3
I think it's got something to do with event propagation. If you create
a function to stop event propagation, the default action is prevented
in the Chrome InfoWindow:

function stop(event) {
if (event.stopPropagation) {
event.stopPropagation();
}
}

<a onclick="stop(event);return false;" href="url">link</a>

...

Yo

unread,
Apr 26, 2010, 8:56:35 AM4/26/10
to Google Maps JavaScript API v3
Thanks, William!

Your solution works for me.

-Y
Reply all
Reply to author
Forward
0 new messages