menardmam
menardmam

Reputation: 9986

JavaScript target question

Here is some code I don't understand, but I know it opens the link in THE SAME WINDOW. I like it to open in BLANK NEW WINOWS... what to add/modify?

[some code before]
_.addEvent(b, 'click', function (e, i) {
document.location.href = (('undefined' !== typeof i) ? i: e.target).getAttribute('flickrshow-u')});_.addEvent(b, 'load', function (e, i) {
[some code after]

I tried to add e.target = "_blank"; before document, but no luck! I got this error: setting a property that has only a getter.

Upvotes: 0

Views: 119

Answers (3)

menardmam
menardmam

Reputation: 9986

here is the code that work :

_.addEvent(b, 'click', function (e, i) { var linkk = (('undefined' !== typeof i) ? i: e.target).getAttribute('flickrshow-u');
                    window.open(linkk, "_blank");

Upvotes: 0

Oded
Oded

Reputation: 499392

A URL assigned to document.location.href will open in the same window. If you pass this same url to window.open, it will open in a new window/tab.

You can read here about the different parameters window.open takes.

Upvotes: 1

Sarfraz
Sarfraz

Reputation: 382909

Rather than document.location.href, you need to use window.open to open a page in new window.

More Info:

Upvotes: 0

Related Questions