Как открыть модальное окно один раз?
помогите понять почему модальное окно с выбором города открывается при каждой перезагрузке?
var part = document.location.href;
if (part == 'https://site.ru/') {
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
if (!getCookie("region")) {
$.fancybox.open({
src: "#region-modal",
type: "inline",
opts: {
afterShow: function () {
$("#region-form").submit(function (event) {
event.preventDefault();
document.cookie = "region=" + $("#region-select").val() + "; path=/";
window.location.href = "https://" + $("#region-select").val() + ".site.ru";
});
},
afterClose: function () {
if (!getCookie('region')) {
setCookie('region', 'true');
}
}
},
});
}
}
<div id="region-modal" class="region-modal" style="display: none;">
<h2>Выберите город отправления</h2>
<form id="region-form" class="region-form">
<select name="region" id="region-select" class="region-select"><?php
foreach( $regions as $city ){ ?>
<option value="<?php echo $city['value'] ?>"><?php echo $city['name'] ?></option>
<?php } ?>
</select>
<button type="submit" class="button region-btn">Выбрать</button>
</form>
</div>