Today, we will see how to show cookie popup in Magento2 on website.
When user open or access first time website, its ask to accept terms policy.
This model popup show until visitors accept or close.
Apply below bootstrap and jquery code to show popup-
HTML code
<div id="cookie-popup-window" style="display:none;"> <p>Accept cookies policy</p> </div>
<script type="text/javascript"> require([ 'jquery','Magento_Ui/js/modal/modal','mage/cookies'], function($,modal) { var options = { type: 'popup', responsive: true, innerScroll: true, title: '', modalClass: 'custom-window-block', buttons: [{ text: $.mage.__('Continue'), class: '', click: function () { this.closeModal(); } }] }; var popup = modal(options, $('#cookie-popup-window')); if ($.cookie('popuplogintext') != 'open') { $("#cookie-popup-window").modal("openModal"); $.cookie('popuplogintext', 'open', { path: '/' });//Set the cookies } }) </script>
Related blog – Custom attribute not saving in Magento2