JavaScript函数中的空白窗口

我正在努力打开一个基于链接的onclick函数的重定向的新窗口。 任何想法,我错了?

该功能的原因是掩盖我们的分支机构网址,通过发送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 &raquo;</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); 当我评论你的代码运行时,trackOutboundLink是undefiend

链接地址: http://www.djcxy.com/p/12427.html

上一篇: blank window in JavaScript function

下一篇: preventDefault() overruled by window.location