_CookieConsentPartial.cshtml 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. <nav id="cookieConsent" class="navbar navbar-default navbar-fixed-top" role="alert">
  10. <div class="container">
  11. <div class="navbar-header">
  12. <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#cookieConsent .navbar-collapse">
  13. <span class="sr-only">Toggle cookie consent banner</span>
  14. <span class="icon-bar"></span>
  15. <span class="icon-bar"></span>
  16. <span class="icon-bar"></span>
  17. </button>
  18. <span class="navbar-brand"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span></span>
  19. </div>
  20. <div class="collapse navbar-collapse">
  21. <p class="navbar-text">
  22. Use this space to summarize your privacy and cookie use policy.
  23. </p>
  24. <div class="navbar-right">
  25. <a asp-page="/Privacy" class="btn btn-info navbar-btn">Learn More</a>
  26. <button type="button" class="btn btn-default navbar-btn" data-cookie-string="@cookieString">Accept</button>
  27. </div>
  28. </div>
  29. </div>
  30. </nav>
  31. <script>
  32. (function () {
  33. document.querySelector("#cookieConsent button[data-cookie-string]").addEventListener("click", function (el) {
  34. document.cookie = el.target.dataset.cookieString;
  35. document.querySelector("#cookieConsent").classList.add("hidden");
  36. }, false);
  37. })();
  38. </script>
  39. }