Hi everyone i want to redirect a user to another page if the cookie is set by clicking the button.
<div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override">
</div>
</div>
Works and i also got the if statement in php but i want it in javascript because of wordpress issues. In php it would look like this.
i can't seem to figure it out in javascript, and i also looked around on the web
After doing this:
<div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override">
</div>
</div>
it keeps going to the redirect even without the cookie
<div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override">
Code:
<a href="" onClick="SetCookie('pecCookie','dit is een cookie','-1')"><button type="button" name="accept" class="btn btn-success">Button Text</button>
<script>
function SetCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+365)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) +
("; path=/")
location.reload()
}
if
</script>
</div>
Works and i also got the if statement in php but i want it in javascript because of wordpress issues. In php it would look like this.
Code:
<?php
$cookie_name = "anyname";
$cookie_value = "anycontent";
If (isset($_COOKIE[$cookie_name])) {
// action if cookie is set
}
?>
i can't seem to figure it out in javascript, and i also looked around on the web
After doing this:
<div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override">
Code:
<a href="" onClick="SetCookie('pecCookie','dit is een cookie','-1')"><button type="button" name="accept" class="btn btn-success">Button Text</button>
<script>
function SetCookie(c_name,value,expiredays) {
var exdate=new Date()
exdate.setDate(exdate.getDate()+365)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) +
("; path=/")
location.reload()
}
mycookieValue = getCookie("pecCookie")
if(mycookieValue) {
window.location = "193.91.113.21/downloads/";
}
function getCookie(c_name) {
var re = new RegExp(c_name + "=([^;]+)");
var value = re.exec(document.cookie);
return (value != null) ? unescape(value[1]) : null;
}
</script>
</div>
it keeps going to the redirect even without the cookie