有问题的页面在这里:
http://ezup.com/csg/gt.html
在Firefox中,警报框会触发,但随后页面将自动转发,而无需等待用户的任何输入。这适用于IE和Chrome,但Chrome似乎无法识别Cookie。
<script type="text/javascript">
$(document).ready(function(){
(".buy > a").click(function(){
//alert($.cookie("firstClick"));
if($.cookie("firstClick") != 1){
$.cookie("firstClick", "1");
alert("You will now be directed to the Shopping Cart page. Please use your browser's back button to return to the CSG store.");
}
else if($.cookie("firstClick") == 1){
}
});
});
</script>
<body>
<ul>
<li class="buy">
<a href="http://store.ezup.eu/ShoppingCart.asp?ProductCode=EC2HSF1010W&ProductCode=EC1010402142T">L
<button type="button">Add to Cart</button>
</a>
</li>
</ul>
</body>
最佳答案
改为将其更改为确认对话框。或在函数http://api.jquery.com/event.preventDefault/中添加prevent default
<script type="text/javascript">
$(document).ready(function(){
prompt
$(".buy > a").click(function(e){
e.preventDefault();
//alert($.cookie("firstClick"));
if($.cookie("firstClick") != 1){
$.cookie("firstClick", "1");
alert("You will now be directed to the Shopping Cart page. Please use your browser's back button to return to the CSG store.");
window.location = $(this).attr(href);
}
else if($.cookie("firstClick") == 1){
}
});
});
</script>