admin管理员组文章数量:1302523
I have modal wizard that shows an instruction in my page. I want to show the modal once per session
Here's my code
<div class="modal fade" id="wizardmodal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Property</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<!-- Smart Wizard HTML -->
<div id="smartwizard">
<ul>
<li><a href="#step-1">Step 1<br /><small>Add Property</small></a></li>
<li><a href="#step-2">Step 2<br /><small>Type of Property</small></a></li>
</ul>
<div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
I'm currently using modal show.
$(window).on('load',function(){
$('#wizardmodal').modal('show');
});
The modal automatically show when i reload the page. What should I do?
I have modal wizard that shows an instruction in my page. I want to show the modal once per session
Here's my code
<div class="modal fade" id="wizardmodal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Property</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<!-- Smart Wizard HTML -->
<div id="smartwizard">
<ul>
<li><a href="#step-1">Step 1<br /><small>Add Property</small></a></li>
<li><a href="#step-2">Step 2<br /><small>Type of Property</small></a></li>
</ul>
<div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
I'm currently using modal show.
$(window).on('load',function(){
$('#wizardmodal').modal('show');
});
The modal automatically show when i reload the page. What should I do?
Share Improve this question asked Sep 5, 2018 at 5:33 Tristan Ross LazaroTristan Ross Lazaro 111 silver badge4 bronze badges 1- use the session variable to check whether the session has started or not. – Exterminator Commented Sep 5, 2018 at 5:37
2 Answers
Reset to default 8Use window.sessionStorage to track whether it's been shown to the user in that session.
$(window).on('load',function(){
if (!sessionStorage.getItem('shown-modal')){
$('#wizardmodal').modal('show');
sessionStorage.setItem('shown-modal', 'true');
}
});
Already answered here
You can use jQuery Cookie:
$(document).ready(function() {
var dialogShown = $.cookie('dialogShown');
if (!dialogShown) {
$(window).load(function(){
$('#wizardmodal').modal('show');
$.cookie('dialogShown', 1);
});
}
});
Or Browser's localStorage:
$(document).ready(function() {
var dialogShown = localStorage.getItem('dialogShown')
if (!dialogShown) {
$(window).load(function(){
$('#wizardmodal').modal('show');
localStorage.setItem('dialogShown', 1)
});
}
});
本文标签: javascriptModal show once per sessionStack Overflow
版权声明:本文标题:javascript - Modal show once per session - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741673726a2391756.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论