_CookieConsentPartial.cshtml 1.0 KB

12345678910111213141516171819202122232425
  1. @using Microsoft.AspNetCore.Http.Features
  2. @{
  3. var consentFeature = Context.Features.Get<ITrackingConsentFeature>();
  4. var showBanner = !consentFeature?.CanTrack ?? false;
  5. var cookieString = consentFeature?.CreateConsentCookie();
  6. }
  7. @if (showBanner)
  8. {
  9. <div id="cookieConsent" class="alert alert-info alert-dismissible fade show" role="alert">
  10. Use this space to summarize your privacy and cookie use policy. <a asp-area="" asp-controller="Home" asp-action="Privacy">Learn More</a>.
  11. <button type="button" class="accept-policy close" data-dismiss="alert" aria-label="Close" data-cookie-string="@cookieString">
  12. <span aria-hidden="true">Accept</span>
  13. </button>
  14. </div>
  15. <script>
  16. (function () {
  17. var button = document.querySelector("#cookieConsent button[data-cookie-string]");
  18. button.addEventListener("click", function (event) {
  19. document.cookie = button.dataset.cookieString;
  20. }, false);
  21. })();
  22. </script>
  23. }