I dynamically add an <a> (link) tag to the DOM with:
var link = document.createElement('a');
link.href = 'http://www.google.com/';
link.onclick = function () { window.open(this.href); return false; };
link.appendChild(document.createTextNode('Google'));
//someDomNode.appendChild(link);
I want the link to open in a new window (I know it's bad, but it's required). I also tried to use the "target" attribute, but I also have the wrong behavior with this solution too.
My code works well in IE and Firefox, but the return false don't work in Safari, Chrome and Opera. By don't work I mean the link is followed after the new window is opened.
I think I might be because of the Google Maps V3 environment...
Edit: To see the behavior on the actual page:
- Go to http://tinyurl.com/29q6nw6
- Click on any marker on the map, a balloon will show.
- Click on the title in the balloon, the link should open in a new window (work in IE and FF but not in Safari, Chrome and Opera.
Any help is welcome!
Edit2: The problem is in function "MakeInfoWindowContent" which is in "gmaps3.js". I don't use DOM to create the elements (I use string) because this HTML string must be passed to Google Maps (for the info window - the balloon). In fact the same link is created at 2 different places. One on the left, created with DOM function (as shown in this question) which works in all browsers and one in the balloon, created with an HTML string, this one don't work well in Safari, Chrome and Opera (the link is followed after the new window open even with the return false).
Edit 3: Still no clue why this is happening... If anyone have an idea, let me know!