"return false" is ignored in certain browsers for link added dynamically to the DOM with JavaScript
- by AlexV
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) and I don't want to use the target attribute.
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.