I am newish to jQuery. I am trying to unset a cookie and then go to the next page.
There are quite a few answers on this subject here and elsewhere. I thought this would be very straightforward but about two hours later I know I must be doing something dumb.
Simple button:
<button class="btn btn-success" id="showInfo">Show intro</button>
Tweaked borrowed function that works nicely:
function setCookie(cookieName, cookieValue, daysToKeep)
{
var d = new Date();
d.setTime(d.getTime() + (daysToKeep*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cookieName + "=" + cookieValue + ";" + expires + ";path=/";
}
"Simple" function call on button click:
<script>
$("#showInfo").on("click", function()
{
setCookie("button1","",-1 );
$(location).attr('href',"2.php");
// window.location.assign("2.php");
// window.location.replace("2.php");
})
</script>
I have tried windows replace
, assign
and href
. I have tried jQuery $(location)
.
I know I am doing something stupid because even when I comment out the setCookie
function call nothing happens with any of these.