Passing variable to window.location href

This question already has an answer here:

  • jQuery location href [duplicate] 6 answers
  • How do I redirect to another webpage? 67 answers

  • 不需要使用jQuery来设置location对象的属性(并且不需要使用jQuery来获取锚对象的href属性):

    $("a.private-product-order-button").click(function(e) {
        e.preventDefault();
        _gaq.push(['_trackEvent', 'Order buttons', 'Click', 'Service']);
    
        var url = this.href;
        setTimeout(function() {
            window.location.href = url;
        }, 200);
    });
    

    Because you're adding string after all.

    It should be:

    $(window.location).attr('href', url);
    

    not

    $(window.location).attr('href', 'url');
    

    Use $(window.location).attr('href', url); without the quotes around url.

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

    上一篇: PHP标头():302移动临时错误

    下一篇: 将变量传递给window.location href