使用 window.location 在 JavaScript 函数中_blank窗口
Using window.location to _blank window in JavaScript function
我正在努力打开一个新窗口,其中包含基于链接的重定向和点击功能。有什么想法我哪里出错了吗?
该功能的原因是掩盖我们的会员网址,通过发送Google Analytics来跟踪点击,并将用户带到带有会员链接的新页面。
目前发生的事情是,当点击时,点击被跟踪,但随后在同一窗口和新窗口中加载会员链接。
JS函数;
$(function()
{
/**
* Affiliate Link Click Listener
* ---
* 1. prevent the default behaviour.
* 2. Grab the affiliate url.
* 3. run google tracking code.
* 4. redirect the user.
**/
$('.affiliate-link').on('click', function(e){
// Prevent default behaviour
e.preventDefault();
// Get the affiliate link
var affiliate_link = $(this).attr('data-link');
console.log(affiliate_link);
// Call our google tracking function
trackOutboundLink(affiliate_link);
// Do the redirect
window.open(affiliate_link, '_blank');
});
});
/**
* Function that tracks a click on an outbound link in Analytics
* This function takes a valid URL string as an argument, and uses that URL string
* as the event label. Setting the transport method to 'beacon' lets the hit be sent
* using 'navigator.sendBeacon' in browser that support it.
*/
var trackOutboundLink = function(url) {
ga('send', 'event', 'outbound', 'click', url, {
'transport': 'beacon',
'hitCallback': function(){document.location = url;}
});
}
链接;
<a class="apply-btn affiliate-link" href="" data-link="<?= $product['tracking_link']?>" target="_blank">SEE DEAL »</a>
我最初window.location.href = affiliate_link;
进行重定向,但一些搜索显示无法定位空白窗口。
$(function()
{
/**
* Affiliate Link Click Listener
* ---
* 1. prevent the default behaviour.
* 2. Grab the affiliate url.
* 3. run google tracking code.
* 4. redirect the user.
**/
$('.affiliate-link').on('click', function(e){
// Prevent default behaviour
e.preventDefault();
// Get the affiliate link
var affiliate_link = $(this).attr('data-link');
console.log(affiliate_link);
// Call our google tracking function
// trackOutboundLink(affiliate_link);
// Do the redirect
window.open(affiliate_link, '_blank');
});
});
此方法中的错误 trackOutboundLink(affiliate_link); 当我注释此行时,您的代码运行
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 防止Iframe窗体在新窗口中打开
- 内部分区字体大小获胜'调整浏览器窗口大小时不会随媒体查询而更改
- 调整窗口大小时,可拖动的对象会出现在容器外部
- Javascript排序的图像弹出窗口..可以't单独弹出
- 窗口大小html css
- 弹出窗口出现,然后退出
- 为什么不是't窗口.恢复正常工作吗?(javascript/jquery)
- Javascript更新孙窗口中的表单元素
- 如何在选项卡上定义属性'的主窗口对象
- CSS-若窗口太小,滚动条会出现在“表格”单元格上
- 召回窗口加载事件 - javascript
- 为什么不显示警报窗口
- 如何使用modalDialog来显示可以在所有浏览器中工作的弹出窗口
- Chrome应用程序调整窗口大小保持纵横比
- 新选项卡被弹出窗口阻止程序阻止
- 如何访问UIWebView'的子窗口上下文
- 刷新父窗口后无法关闭窗口
- 自动关闭弹出窗口的Javascript
- Facebook Connect Blank 弹出窗口在 Chrome 上