Joe
Joe

Reputation: 25

Window location target _blank

Hi I have this problem with window location target and cannot solve it. I'm doing some GA tracking for links through out my page and I want to add target location _ blank. the code is this

$(".ga_track").click(function (event) {
  event.preventDefault();
  var href = $(this).attr('href');
  var label = $(this).attr('data-description');
  ga('send', 'event', 'Link Clicked', 'Click Details', label, {
    'hitCallback': function () {
      window.location.href = href;
      window.location.target = blank;
    }
  });


});

Upvotes: 0

Views: 15769

Answers (3)

鄭有維
鄭有維

Reputation: 265

You should try like

<a target="_blank" onclick="ga(...);window.open(URL, name, specs, replace);return false;"> </a>

Upvotes: 0

Nitesh
Nitesh

Reputation: 1550

What you are trying to do is fundamentally incorrect.

You are doing window.location.href which means, you are doing it in current window then how can you set it to target?. That is why there is no such target property in window.location.

If you want any such behavior create one anchor ("a") element and then set target and href attributes on that and then trigger click on that.

or use window.open for another window

Upvotes: 1

Stefdelec
Stefdelec

Reputation: 2811

You should use this function

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

https://www.w3schools.com/jsref/met_win_open.asp

And duplicate question: How to open a URL in a new Tab using javascript or jquery?

Upvotes: 1

Related Questions