前提・実現したいこと
アクセス時に1度だけ表示するモーダルウインドウを設置したのですが×ボタンを押したときのみクローズさせたいのですができません。
発生している問題・エラーメッセージ
×ボタン以外の部分をクリックしても消えてしまいます
該当のソースコード
<script> window.onload = function() { if( !sessionStorage.getItem('disp_popup') ) { sessionStorage.setItem('disp_popup', 'on'); var popup = document.getElementsByClassName('bg_onetime_popup'); popup[0].classList.add('js_active'); popup[0].onclick = function() { popup[0].classList.remove('js_active'); } } } </script> </script></script> </script><div class="bg_onetime_popup"> <div class="onetime_popup"> <p class="onetime_popup_title">タイトル</p> <div class="onetime_popup_content"> <p>テキスト<script> window.onload = function() { if( !sessionStorage.getItem('disp_popup') ) { sessionStorage.setItem('disp_popup', 'on'); var popup = document.getElementsByClassName('bg_onetime_popup'); popup[0].classList.add('js_active'); popup[0].onclick = function() { popup[0].classList.remove('js_active'); } } }
</div><div class="bg_onetime_popup"> <div class="onetime_popup"> <p class="onetime_popup_title">タイトル</p> <div class="onetime_popup_content"> <p>テキスト</p> </div> </div>
<style> .bg_onetime_popup { position: fixed; top: 0px; left: 0px; z-index: 9999; width: 100vw; height: 100vh; background-color: rgba(0, 0, 0, 0.5); opacity: 0; visibility: hidden; transition: 0.5s;
}
.bg_onetime_popup.js_active {
opacity: 1;
visibility: visible;
}
.onetime_popup {
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
width: 50%;
min-width: 500px;
background-color: #fff;
cursor: pointer;
}
.onetime_popup_title {
position: relative;
padding: 30px 90px;
margin: 0px;
background-color: #23282D;
color: #fff;
font-size: 24px;
text-align: center;
line-height: 1.5;
}
.onetime_popup_title:before,
.onetime_popup_title:after {
position: absolute;
top: 50%;
right: 30px;
transform: translateY(-50%);
width: 30px;
height: 4px;
background-color: #fff;
content: "";
}
.onetime_popup_title:before {
transform: rotate(45deg);
}
.onetime_popup_title:after {
transform: rotate(-45deg);
}
.onetime_popup_content {
padding: 60px 30px;
text-align: ;
}
</style></p>
</div>
</div>
<style> .bg_onetime_popup { position: fixed; top: 0px; left: 0px; z-index: 9999; width: 100vw; height: 100vh; background-color: rgba(0, 0, 0, 0.5); opacity: 0; visibility: hidden; transition: 0.5s;
}
.bg_onetime_popup.js_active {
opacity: 1;
visibility: visible;
}
.onetime_popup {
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
width: 50%;
min-width: 500px;
background-color: #fff;
cursor: pointer;
}
.onetime_popup_title {
position: relative;
padding: 30px 90px;
margin: 0px;
background-color: #23282D;
color: #fff;
font-size: 24px;
text-align: center;
line-height: 1.5;
}
.onetime_popup_title:before,
.onetime_popup_title:after {
position: absolute;
top: 50%;
right: 30px;
transform: translateY(-50%);
width: 30px;
height: 4px;
background-color: #fff;
content: "";
}
.onetime_popup_title:before {
transform: rotate(45deg);
}
.onetime_popup_title:after {
transform: rotate(-45deg);
}
.onetime_popup_content {
padding: 60px 30px;
text-align: ;
}
</style>
どうかよろしくお願いします。