I have a web2.0 app that uses the Google Maps API and takes a while to load. I'd really like to have the links for the Google logo and Terms on the map open in a new window so that if the user clicks on them, that user won't have to reload my app when he/she goes back to it. Has anyone gotten this to work or seen it somewhere?
Hi, I am struggling with the same problem. I have been able to solve the problem of opening a link in the same frame changing window.top.location to window.self.location in the following part of script:
function createMarker(point,icon,gotoURL,name) { var marker = new GMarker(point, {icon:icon, title:name}); GEvent.addListener(marker, "click", function() { window.top.location=gotoURL; }); return marker;
window.parent.location seems to work as well. (note: top, self and parent, without "_") So it seems window.xxx.location understands xxx as the window where to open, at least the standard terms. But unfortunately using window.blank.location seems to not only not open in another window, but even eliminate the link-function.... (also tried with window._blank.location), let alone trying to open in a window with a customized name, which is what I try to achieve....
window.xxx will only work where xxx is an existing window (or a special one like top, self, etc). If you use a name which isn't recognised, the call will fail -- and in an event handler, the error will be suppressed. To open a new window, you need window.open(url,name,features,replace);
url is the URL which should go in the new window; name is the name to give it (to use with the window.xxx reference later); you can also reference an existing window with its name; features is the list of screen features like toolbars, status bar, etc. If you omit this you get a default window; replace, used with an existing window, specifies whether its history is to be replaced.
I doubt that this will help with the TOU link, though.
Thanks Andrew, but I don't fully understand.. Should "window.open(gotoURL,name);" substitute "window.name.location=gotoURL; " Where and how should it be fit in my "function createMarker" example? Oh, and the "TOU" link? Sorry I'm a little tired...
Yes: window.name.location will only work if there's a window/frame called "name". Using window.open(gotoURL,name) will work all the time, whether or not it already exists.
In your createMarker, replace window.top.location=gotoURL; with window.open(gotoURL,name); which will show your "gotoURL" page in a window called "name".
That may be a bad example: I don't think I would use "name" because that might be a reserved word.
My remark about the TOU link referred to the OP: I don't think it's possible to alter the target of the TOU link.
It's not working Andrew :-( I've tried several alternatives, but whenever I put a name the link gets lost. Only window.open(gotoURL) opens the link (in a new window).
You need to specify the name of the new window as a string: window.open(gotoURL,"SOL"); otherwise it tries to use the value of a variable called SOL (I think). Putting it in quotes will call the new window "SOL".
Great! Working!!! And the link DOES open up in window "SOL" when it exists. The idea is to use "SOL" as the main window for information and "SOL2" for large graphic stuff like maps and photoalbum. My "dream" is that if someone hits a marker on the map in SOL2 I want the info to open up again in SOL and people can jump from one to another. Now the dream can be true! :-)
Back to my original question, I've figured out how to get the terms link to open in a new window, but not the logo. I think the logo uses a javascript function, not an anchor tag.
Here's my code (Note, this is in Java using GWT):
Stack elements = new Stack();
elements.push( this.gmapWidget.getElement() );
while ( !elements.isEmpty() ) { Element e = (Element) elements.pop();
String href = DOM.getAttribute( e, "href" ); if ( href != null && href.endsWith( ".html" ) ) { DOM.setAttribute( e, "target", "_blank" ); } for ( int i = 0; i < DOM.getChildCount( e ); i++ ) { elements.push( DOM.getChild( e, i ) ); }
When you click on the logo, you are sent to the site from which you downloaded the API code, with parameters that will open the map there with the same center and span as your currently displayed map, with same host language, and same overview map state. This URL is generated in code by the click handler, so it may not be so easy to subvert.
Bear in mind that your site visitors will be familiar with those links from using http://maps.google.com, other Maps API pages, or from previous visits to your page. Your page test scripts need to be designed within this larger context. Your actual visitors may be less likely to follow these links than your test script results suggest. While a push every button, click every link strategy is good for completeness, it does not reflect the actual usage patterns of your visitors.
I agree that most users will not want to click on the logo. However, the border between the logo and the map is unclear. Meaning, when your mouse is on the edge of the logo, your mouse events are sent to the map, no the logo link. I just envison someone trying to pan as much as possible from the lower left corner and accidentally clicking the logo instead of the map because the transition (meaning when the mouse pointer changes) is not the exact border of the logo.
Anyway, those of you working at Google, I'd really appreciate (in a future release) a way to set which window the logo link opens in. I would think this behavior would be within the rules of the terms.