如何在一个会话中只显示一次横幅



我已经创建了一个引导模式的横幅(它将显示在仪表板页面,如果条件满足)。如果我们关闭按钮,它会消失,它工作正常

但问题是,当我关闭横幅,如果我去任何页面,当我回到仪表板页面再次显示。

我的要求是在会话中只显示一次横幅(使用会话存储),当关闭并转到另一个页面时,如果我回到仪表板页面,它不应该显示。

index.cshtml

@if (Model.IsOptinEligible)
{
<div class="member-eligibility-popup">
<div id="memberEligibilityPopup" class="modal fade modalPopup" role="dialog" data-backdrop="static" data-keyboard="false" tabindex="-1">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-body modal-body-content">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h3 class="modal-title bannerModalTitle">["You have access to Coaching!"]</h3>
<div class="row">
<div class="col-sm-8">
<p class="modalContent">["A coach can work with you to create a personalized plan and help make sure you stay on track to reach your goal."]</p>
</div>
<div class="col-sm-4">
<a href="#" class="banner-modal-button">@_Localized["Get Started Now"]</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
}
@if (Model.IsOptinEligible == true)
{
<script>
$(function () { $("#memberEligibilityPopup").modal('show'); });
</script>
}

有人能帮我一下吗?

使用会话存储

if(!sessionStorage.getItem('shown')) { 
/* show it here */
// Mark it as shown
sessionStorage.setItem('shown', '1');
}

最新更新