Inconsistent browser behavior when opening URLs directly from marker

60 views
Skip to first unread message

Roger Ertesvag

unread,
Nov 21, 2011, 3:38:58 PM11/21/11
to google-map...@googlegroups.com
I'm trying to make a map where clicking a marker opens an URL directly without opening an info window first. I have implemented it by adding a listener that uses the window.open function:

  google.maps.event.addListener(marker, "click", function() {
    window.open('http://www.example.com/');
  });

This works great in Firefox, Opera, IE9 and iOS. But in Chrome, Safari for windows and older versions of IE the URL opens in a window or tab behind the map. Strangely, in Chrome using rightclick instead works, but obviously this is not very practical and also most other browsers block this as an illegal popup.

I have made an example page with a marker that implements both left click and right click:

http://www.kamerakartet.no/gmaps_test

To me this looks like a bug that should be fixed? Or maybe there is another way to code this that works better? Any suggestions would be highly appreciated!


Regards
Roger

Marcelo

unread,
Nov 21, 2011, 4:43:35 PM11/21/11
to Google Maps JavaScript API v3

MymsMan

unread,
Nov 21, 2011, 6:00:42 PM11/21/11
to google-map...@googlegroups.com
Why would leftclick and rightclick act differently with identical functions defined?

Roger Ertesvag

unread,
Nov 22, 2011, 2:00:49 AM11/22/11
to google-map...@googlegroups.com
Marcelo,
while windows.open may not be cross browser, the issues here does not occur when used outside of Google maps. I have added a regular link using window.open to the example page, this opens in the foreground regardless of which browser is used.


Roger

Martin™

unread,
Nov 22, 2011, 2:16:04 AM11/22/11
to Google Maps JavaScript API v3
Hi.

Look at the syntax of the window open method:

http://www.w3schools.com/jsref/met_win_open.asp

Have you experimented with the 'name' attribute to see if you can get
the behaviour you desire?

Martin.

Pil

unread,
Nov 22, 2011, 2:39:29 AM11/22/11
to Google Maps JavaScript API v3

On Nov 21, 9:38 pm, Roger Ertesvag <webfo...@webfokus.no> wrote:

> http://www.kamerakartet.no/gmaps_test
>
> To me this looks like a bug that should be fixed? Or maybe there is another
> way to code this that works better? Any suggestions would be highly
> appreciated!

Very non-professional, annyoing, confusing behaviour because nobody
would expect that a marker will be misused to open a new browser
window or tab.

I'd call this a bug intended by design.

Roger Ertesvag

unread,
Nov 22, 2011, 2:55:57 AM11/22/11
to google-map...@googlegroups.com
Martin,
I have tried with the '_blank' option, but it has the same problem. The others would open the link in the same window, which is not what I'm looking for.


Roger

Roger Ertesvag

unread,
Nov 22, 2011, 3:01:53 AM11/22/11
to google-map...@googlegroups.com
Pil,
what makes you say this is misusing a marker? If all you want to do with a marker is to open a link I see no reasen not to be able to do this directly, instead of opening an info window first and making the user click twice for every link.


Roger

Pil

unread,
Nov 22, 2011, 3:33:53 AM11/22/11
to Google Maps JavaScript API v3
Well, the difference is that, when a user clicks on a link, he/she
intends to open a new page.
(And the address of that new page should be visible in the 'status
bar'. That's the intention of the 'status bar').
But when the user clicks on a marker he/she would never expect this
behaviour. The user would be forced to play some sort of roulette.

Without doubt: Javascript can be (mis)used to force people to unwanted
actions.
There are many examples of annyoing and even risky and dangerous
scripts.

Most of these annoyances and risks can be avoided by using NoScript
which I use regularly because I know what's possible.

http://noscript.net/

Marcelo

unread,
Nov 22, 2011, 11:02:05 AM11/22/11
to Google Maps JavaScript API v3

Yes, but window.open() is not part of any W3C specification or
technical recommendation. Furthermore, there are also differences on
how it is handled between various versions of the same browser and
between different operating systems. Therefore I don't think the issue
can be blamed on the API.

The different behavior could be due to the fact that, when you click
the marker, window.open is being called from wihtin a callback
function, while your other link, outside the API is direct.

See
https://developer.mozilla.org/en/DOM/window.open

most importantly:
<quote>
Specification
DOM Level 0. window.open() is not part of any W3C specification or
technical recommendation."
</quote>

and

<quote>
Never use this form of code for links:
<a href="javascript:window.open(...)" ...>

"javascript:" links break accessibility and usability of webpages in
every browser.
</quote>

Marcelo

unread,
Nov 22, 2011, 11:05:12 AM11/22/11
to Google Maps JavaScript API v3
On Nov 22, 12:39 am, Pil <wolf...@gmail.com> wrote:
> Very non-professional, annyoing, confusing behaviour because nobody
> would expect that a marker will be misused to open a new browser
> window or tab.

I often have to write code that I don't like because my client
requested it, but the client often has a good reason for it. :-)

Roger Ertesvag

unread,
Nov 22, 2011, 1:50:03 PM11/22/11
to google-map...@googlegroups.com
It was not my intention to blame anyone or anything. While I mentioned the possibility of it being a bug in the original question I also said that there may be a better way to code it than my suggestion.

I still think the option of accessing links directly from a google map without an infowindow would be very useful for some applications, but I understand yours and others objections to the way it was implemented in the example.


Roger
Reply all
Reply to author
Forward
0 new messages