Search code examples
javascripthtmlgoogle-chromehyperlinkhref

Simulation an href in chrome to open a new tab, not window. Not using onclick


and pardon my english

I have a specific problem with Chrome browser, just in chrome.

If I use a simple link, like

<a id="a1" href="http://www.stackoverflow.com" target="_blank">Need to simulate user clicking on this link, but no the onclick event</a>

The browser open the url in a new tab, so far, perfect.

My problem comes in the moment I try to do it in a javascript function.

For example, if I try to emulate the event onclick, like

$("#a1").onclick(); // Jquery is welcome

The chrome browser open a new window, and I need a tab.

So, I'm not trying to emulate the click event, just the href, I don't know how to call it. Or find the way to force in a window.open("url", "newwindow", "params", t/f );

I'm using asp.net, using an extra form to try to change the action and submit is not and option, it disappears.

For firefox and explorer I use, in a function

PopUpWindow = window.open("url", 'newWindow' + Guid, 'toolbar=0, menubar=0, location=1, status=0, scrollbars=0');

And is working well. I think I don't need the param, because the window is open as a tab.

My browser have the default settings, and I know that depending on the browser settings, you can open a window or tab by clicking the link (I checked for similar answers). So my intention is to try to emulate the href not the click event.

Or, there are any way to manage the tabs in chrome?,

Thanks in advance


Solution

    1. I don't think its possible, it would be against all browser rules to force open a tab.

    2. Tabs are a setting in your browser, not every user wants to use tabs. It's almost always better to let the user control this kind of behavior instead of forcing this upon them.

    To open a new window (or tab if the user set this in his/her settings) use:

    window.open(
      url,
      '_blank' // new window or tab.
    );