Yes, I know, there is an answer to the same question on the 22may (a week ago), but I've tried the same solution, it's specified before the actual "calling" to the toastr script, I've even tried with both : and = but I can't resolve the issue.
The first code is the whole page, including the "check if a cookie is set, if not, display toastr and set a cookie" script.
This one works, except the "options". It displays 2 toastr on the screen
<!DOCTYPE html><html><head><meta charset=utf-8>
<link href="https://my.site.se/js/toastr.css" rel="stylesheet" type="text/css" />
<script src= "https://my.site.se/js/jquery-3.2.1.js"></script>
<script src="https://my.site.se/js/toastr.js"></script>
<!-- createCookie funktion -->
<script>
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
</script>
<script>
<!-- see if the i agree cookie is set, else send them to the info page -->
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
toastr.options = {
"closeButton": true,
"debug": false,
"newestOnTop": false,
"progressBar": true,
"positionClass": "toast-top-left",
"preventDuplicates": false,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}
$(function () {
toastr.options.closeButton: true;
toastr.options.progressBar=true;
toastr["error"]("We use Cookies!","Cookies!")
});
$(function () {toastr["info"]("We have now created a cookie that prevents this information from being displayed again, unless you remove the cookie of course\n Read the terms page for more info\n To delete ALL your cookies, press the delete cookies button!")});
}
</script>
</Head>
<body>
<script>
readCookie('acceptterms');
</script>
<script>
createCookie('acceptterms','yesIdo',3650);
</script>
The code is in the head, if I place it in the body it won't work at all, I've even tried:
$(function () {toastr.option.progressBar= true;
toastr["error"]("We use Cookies!","Cookies!")
});
I also tried to set the
toastr.options = { "closeButton": true, "debug": false, "newestOnTop": false, "progressBar": true, "positionClass": "toast-top-left", "preventDuplicates": false, "showDuration": "300", "hideDuration": "1000", "timeOut": "5000", "extendedTimeOut": "1000", "showEasing": "swing", "hideEasing": "linear", "showMethod": "fadeIn", "hideMethod": "fadeOut" }
In the body.. And a few I can't even remember now.. I just can't understand why it's so hard to set the options...
It would be easier if the options could be changed in the script itself, but there are some I can't find in there..