1

I have a great working code that opens a link in the same window when I click it, it's inside a dropdown menu.

This is in javascript.

problem is that I would like it to open up in a new tab instead of the same window. How can I do this?

here is my code:

items["linkeee"] = {
    "label": "mylabel",
    "action": function(obj) {
        openUrl('http://mypageaa.com/page' + addId);
    }
};

update -- also my html looks like this:

<a href="#">mylabel</a>

BUT I don't have direct access to the html without messing stuff up. I gotta do this up there with the javascript

update

how do i combine 'http://mypageaa.com/page' + addId to add , "_blank"

please help thanks

diyguy
  • 43
  • 8

4 Answers4

1

use window.open instead of your openUrl method, but new window is not guaranteed to open, the browser may block it.

Liang
  • 507
  • 2
  • 9
1

From what I have read in the documentation and several other answers, It appears this behavior depends on user-preference / (user)browser configuration.

From JavaScript's side, there's nothing you can do to reliably open an URL in a new tab

See: Open a URL in a new tab (and not a new window) using JavaScript

Documentation http://www.w3schools.com/jsref/met_win_open.asp

Community
  • 1
  • 1
rtcode
  • 103
  • 9
1

Turn off pop-up blockers for the domain at browser preferences or settings, see chrome Pop-up blocker when to re-check after allowing page. Use window.open()

var w;
items["linkeee"] = {
    "label": "mylabel",
    "action": function(obj) {
        w = window.open("http://mypageaa.com/page", "_blank");
    }
};

Alternatively, use <a> element at html with target attribute set to "_blank"

<a href="http://mypageaa.com/page" target="_blank">mypageeaa</a>

Using javascript

var a = document.createElement("a");
a.href = "http://mypageaa.com/pagee" + addId; // `encodeURIComponent(addId)`
a.target = "_blank";
document.body.appendChild(a);
a.click();
Community
  • 1
  • 1
guest271314
  • 1
  • 15
  • 104
  • 177
0

I suggest using the method

window.open(URL, name, specs, replace);

It defaults to opening a new window. (tab vs window is a user preference)

documentation here.

Andy Mac
  • 369
  • 2
  • 9