admin管理员组文章数量:1390503
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;
}
});
});
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;
}
});
});
Share
Improve this question
asked Mar 15, 2017 at 7:19
JoeJoe
251 gold badge1 silver badge6 bronze badges
3 Answers
Reset to default 1You should use this function
window.open(URL, name, specs, replace)
https://www.w3schools./jsref/met_win_open.asp
And duplicate question: How to open a URL in a new Tab using javascript or jquery?
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
You should try like
<a target="_blank" onclick="ga(...);window.open(URL, name, specs, replace);return false;"> </a>
本文标签: javascriptWindow location target blankStack Overflow
版权声明:本文标题:javascript - Window location target _blank - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744668971a2618707.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论