Edge或Safari未读取Cookie

时间:2018-03-15 09:59:28

标签: javascript jquery cookies safari microsoft-edge

我遇到了Safari或MS Edge无法读取Cookie的问题。它在所有其他浏览器中工作正常,而不是在这2个中。 有没有人遇到类似的问题?如果是这样,你是如何设法解决的?谢谢。

$('.primary-button.eligibility-button').mousedown(function() {

var selectedCard = $('input[name="cardInterestOption"]:checked').next().text();
var balanceTransferOption = $('input[name="balanceTransferOption"]:checked').next().text().replace(/[a-z]/g,'');
var annualIncome = parseFloat($( "input[name='annualIncome']").val());
var otherIncome = parseFloat($( "input[name='otherIncome']").val());
var totalIncome = annualIncome + otherIncome;
document.cookie = "creditCardSelectorEligibility=" + selectedCard + "; path=/;";
document.cookie = "creditCardBalanceTransfer=" + balanceTransferOption + "; path=/;";
document.cookie = "creditCardTotalIncome=" + totalIncome + "; path=/;";

});

(function() {
var page = "";
var percentage = "NA";
var path = location.pathname;
if(/results/.test(path)){
    page = "Success";
    var results = "";
    var percent = $(".results-banner:eq(0)").text();
    if(/\b[0-9]{2}/.test(percent)){
        results = percent.match(/\b[0-9]{2}/)[0]
    }
}
else if(/verify/.test(path)){
    page = "Verify";
}
else if(/problem/.test(path)){
    page = "Problem";
}
else if(/noteligible/.test(path)){
    page = "Not Eligible";
}
else if(/unavailable/.test(path)){
    page = "Unavailable";
}

var selectedCard = bt_cookie('yrd_creditCardSelectorEligibility')
var balanceTransferOption = bt_cookie('yrd_creditCardBalanceTransfer')
var totalIncome = bt_cookie('yrd_creditCardTotalIncome')

return page + "|" + selectedCard + "|" + balanceTransferOption + "|" + totalIncome + "|" + results;

})();

1 个答案:

答案 0 :(得分:0)

我们发现有时发生的事情是页面加载太快而无法创建cookie。所以我们不得不改变创建Cookie的方式。例如,当用户与表单交互时,您可以更改代码以创建Cookie。即:如果选择一个按钮或填写一个字段。在那里捕获cookie,而不是在客户必须单击提交的页面末尾。希望这有道理吗?