server1257 server1257 - 24 days ago 7
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('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

Answer

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();