views:

193

answers:

4

Hi,

I need to open links with javascript (window.open) when the user clicks on positions in a google-maps map.

How do I make the user understand that it is a link, that he can click it, and where he will end up when he has clicked it?

Among other things, while the user is hovering over a map position, the URL of that position should be shown in the status-bar, just like with a normal link in firefox.

How do I do that?

Thanks

dontomaso

A: 

Ok I don't know much about how google map manage JS code so I try to give you a general help:

you could create a DIV (with width and height of the rectangular area you want) and then put it with background-color transparent positioned in absolute coordinates where you want into the map.

then write onmouseover and onclick handlers for it so when the user goes over on it you do a change to the mouse shape (from pointer to hand) and when it clicks it open the url.

for the status bar when the user over on a map poistion you can do:

window.status = (getURL)
xdevel2000
It should be noted that window.status doesn't work in firefox unless you check a javascript option "Change status bar text". Also, I'm not sure if the div-link will change colour depending on if it's been visited in the past?
Annan
You can simulate that. You can write a namespaced variable to store DIV-link status:var DIV_status = {visited: false, hover: false, ...,}and accordingly change its color:if(DIV_status.visited){ document.getElementById("div").className = "..." // or document.getElementById("div").backgroundColor = "..."}
xdevel2000
ops notdocument.getElementById("div").backgroundColor = "..." } butdocument.getElementById("div").style.backgroundColor = "..." }
xdevel2000
+1  A: 

You can create a simple link and then put an onclick listener on it using unobtrusive Javascript techniques. When the user clicks the link you intercept the click event, prevent the default action, read the href attribute and open the window. Kinda like this:

<a href="http://www.example.com" id="myLink">link</a>

$("#myLink").on("click", function(event) {
    event.preventDefault();
    myFunctionToOpenWindowForUrl(this.href);
});

This is using jQuery, of course you could adapt it to any other JS library you might be using. This way you will also see the original URL in the status bar, because that is the natural thing for a link - no need for extra coding. Also your links will work even without Javascript, which makes this approach way better than styling a span for instance to look like a link and then attach the listener to it.

VoY
A: 

You can modify the cursor to appear as a pointer by using CSS(cursor:pointer;)

Furthermore, you can put the destination into the title tag, so the user will see the destination if he moves the mouse over the element.

A: 

try something like this:

<a href="javascript:void(0);" onclick="yourAction()" onmouseover="window.status='status bar';">link</a>

href="javascript:void(0);" will show link as it should, if you would put here href="#" it would just scroll on top of the page. Href has to be set to have usual link display.

onmouseover="window.status='status bar';" will set status in window on mouse over.

Andrija