you can try this way..!
app/code/VENDOR/MODULE/view/frontend/layout/default.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="before.body.end">
<block class="VENDOR\MODULE\Block\Popup" name="popup.config" template="VENDOR_MODULE::popup.phtml" />
</referenceContainer>
</body>
</page>
app/code/VENDOR/MODULE/Block/Popup.php
<?php
namespace Vendor\Module\Block;
class Popup extends \Magento\Framework\View\Element\Template
{
public function __construct
(
\Magento\Framework\Stdlib\CookieManagerInterface $cookieManager,
\Magento\Framework\View\Element\Template\Context $context
)
{
$this->_cookieManager = $cookieManager;
parent::__construct($context);
}
public function getShowPopup()
{
$showpopup = $this->_cookieManager->getCookie('showpopup');
if(!empty($showpopup) && $showpopup == 'no')
return 'no';
else
return 'yes';
}
}
app/code/VENDOR/MODULE/view/frontend/templates/popup.phtml
<?php if($block->getShowPopup() != 'no'): ?>
<div id="popup-modal">
Hiren Goswami
</div>
<script type="text/javascript">
require(['jquery', 'Magento_Ui/js/modal/modal', 'mage/cookies'],function($, modal, cookies)
{
var options = {
type: 'popup',
responsive: true,
innerScroll: true,
buttons: [{
text: $.mage.__('Continue'),
class: 'mymodal1',
click: function ()
{
console.log('Continue...')
}
}]
};
var popup = modal(options, $('#popup-modal'));
$('#popup-modal').modal('openModal').on('modalclosed', function()
{
$.cookie('showpopup', 'no', { path: '/' });
});
});
</script>
<?php endif; ?>