Change map overlay function to open link in new window

Posted on 2008-11-18
Last Modified: 2012-05-05
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 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 "" Lng "+point.lng()+"<br>Link: <a href=\"http://"+link+"\">www<a/>");


	return marker;


Open in new window

Question by:sara_bellum

    Author Comment

    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)
    LVL 75

    Expert Comment

    by:Michel Plungjan
    You mean

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

    Note I changed the wrong <a/> too

    Author Comment

    Brilliant! I had tried the same approach earlier but made mistakes, and failed to catch the closing href error 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 :)
    LVL 75

    Accepted Solution

    This will handle popup blockers too:

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

    Open in new window


    Author Closing Comment

    Thank you so much!! On to the drudgery of checking lat/longs...

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    There is basically two types of AJAX request in mootools. Request  and Request.HTML Request: Request is the basic XHR request class in MooTools. While not extremely useful on its own, it provides the basic functionality for both Request.HTM…
    Introduction HyperText Transfer Protocol ( or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now