server1257 server1257 - 9 months ago 34
Javascript Question

How to open javascript items array in a new window instead of the same window?

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('' + 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


how do i combine
'' + addId
to add
, "_blank"

please help thanks

Answer Source

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

var w;
items["linkeee"] = {
    "label": "mylabel",
    "action": function(obj) {
        w ="", "_blank");

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

<a href="" target="_blank">mypageeaa</a>

Using javascript

var a = document.createElement("a");
a.href = "" + addId; // `encodeURIComponent(addId)` = "_blank";