Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 833691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:33:26+00:00 2026-05-15T04:33:26+00:00

I dynamically add an <a> (link) tag to the DOM with: var link =

  • 0

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:

  1. Go to http://tinyurl.com/29q6nw6
  2. Click on any marker on the map, a balloon will show.
  3. 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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:33:27+00:00Added an answer on May 15, 2026 at 4:33 am

    Would preventing default action for the event work maybe? Not sure if gmaps handles links in it’s info window in some other way, if not, it should work.

    Update: first example didn’t work. The event wasn’t passed when using “inline” onclick to assign event. This one is tested and found to be working.

    function bindEvent(target, event, handler) {
        if (typeof target.addEventListener != 'undefined') {      
            target.addEventListener(event, handler, false);
        } else if (typeof target.attachEvent != 'undefined') {
            target.attachEvent('on' + event, handler); 
        } 
    }
    
    var link = document.createElement('a');
    link.href = 'http://www.google.com/';
    link.appendChild(document.createTextNode('Google'));
    
    bindEvent(link, 'click', function (e) { 
        if (typeof e.preventDefault != 'undefined') {
            // Common/W3C events
            e.preventDefault();
        } 
    
        // (Old) IE specific events
        e.returnValue = false; 
    
        var target = e.target || e.srcElement;
        window.open(target.href); 
    
        return false; 
    });
    
    document.getElementsByTagName('body')[0].appendChild(link);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.