Reputation: 25
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
Reputation: 265
You should try like
<a target="_blank" onclick="ga(...);window.open(URL, name, specs, replace);return false;"> </a>
Upvotes: 0
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
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