• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1432
  • Last Modified:

Change map overlay function to open link in new window

I inherited a google map overlay that displays station icons with station name labels.  If you click on the icon, you get another label with more station information and a link to the weather station condition page. Unfortunately, the link opens in the same window as the map: to return to the map, you have to press the "back button" key in the browser, which is not user-friendly.  

I want the link to open to a new window (preferably) or tab, whatever google maps supports. Their reference page at  http://code.google.com/apis/maps/documentation/reference.html probably answers the question but I can't find a way to apply the code in a way that works.  The function below is the one I'm trying to change.  The javascript file that it belongs to is attached - it's one of several files that we're using to make this work, but I don't think the others relate to the problem (the map and overlays show up in the html page; the labels correctly import from an xml file; the links I'm trying to open from the map labels are pre-existing html and shtml pages that reside on our server).
function stationMarker(station_name, point, icon, link) {
	var marker = new GMarker(point, icon);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml("Station Name: "+station_name+"<br>Location: Lat "+point.lat()+" Lng "+point.lng()+"<br>Link: <a href=\"http://"+link+"\">www<a/>");
	});
	return marker;
}

Open in new window

gmap2.txt
0
sara_bellum
Asked:
sara_bellum
  • 3
  • 2
1 Solution
 
sara_bellumAuthor Commented:
I should mention that this problem exists for all browsers and platforms that I've tested (Linux and Windows clients with Firefox and IE, with preferences/options set to open new links in new tabs and/or windows)
0
 
Michel PlungjanIT ExpertCommented:
You mean

Link: <a href=\"http://"+link+"\" target=\"_blank\">www</a>"

Note I changed the wrong <a/> too
0
 
sara_bellumAuthor Commented:
Brilliant! I had tried the same approach earlier but made mistakes, and failed to catch the closing href error too...is there a way to set the window size so that it appears to pop up?  I know this is beyond the scope of my original question but thought I'd try my luck :)
0
 
Michel PlungjanIT ExpertCommented:
This will handle popup blockers too:

<a href=\"http://"+link+"\" target=\"_blank\" onClick=\"var w=window.open(this.href,this.target,'width=300,heigth=400'); return (w)?false:true;\">www</a>"

Open in new window

0
 
sara_bellumAuthor Commented:
Thank you so much!! On to the drudgery of checking lat/longs...
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now