-
-
Notifications
You must be signed in to change notification settings - Fork 369
Custom service deny EN
The following function is automatically executed when the user refuses cookies or has not yet accepted them :
"fallback": function () {
"use strict";
// when user deny cookie
}
This function has several uses, such as, for example, modifying the HTML to remove white spaces that are normally occupied by a script that the user has chosen to block (such as ads).
But in this case it is basic js, we will rather focus on the possibilities offered by tarteaucitron.
Dans le cas où l'utilisateur se trouve sur une page qui nécessite un script qu'il a choisi de bloquer, tarteaucitron.fallback () permet de lui suggérer facilement d'activer le script afin d'utiliser les services du site.
Take the example of a site that offers to display the weather forecast to the user. Imagine that this site uses an API which deposits cookies to display the weather and that the user has chosen to block cookies.
As the script is blocked the user can no longer access the weather forecast, it is therefore imperative to suggest that he activate the script !
Nothing could be simpler, just create a div in which to display the message:
<!-- HTML file -->
<div class="myServiceError"></div>
And finally in the fallback function of our service:
"fallback": function () {
"use strict";
var id = 'mycustomservice';
tarteaucitron.fallback(['myServiceError'], tarteaucitron.engage(id));
}
This way in the div it will automatically place a "mycustomservice is disabled" message followed by an "Allowed" button.
If the user clicks on "Authorized", the error message remains visible, so you have to empty the parent div in the function called when cookies are accepted:
"js": function () {
"use strict";
// When user allow cookie
document.getElementByClassName('myServiceError').innerHTML = '';
},
And here is the message is activated and deactivated automatically !