简体   繁体   English

按下后退浏览器按钮时隐藏 jsp 页面上的 div

[英]Hide div on jsp page when back browser button is pressed

Well I have a "jsp1" which contains a div with a button.好吧,我有一个“jsp1”,其中包含一个带按钮的 div。 Once the div button is pressed, it takes me to the next "jsp2".按下 div 按钮后,它会将我带到下一个“jsp2”。 However, if the "back" browser button is clicked, I need the div button on "jsp1" to be hidden and prevent the user from click it, and if possible show other div that is already hidden.但是,如果单击“后退”浏览器按钮,我需要隐藏“jsp1”上的 div 按钮并防止用户单击它,并尽可能显示其他已隐藏的 div。 How can I achieve this using no frameworks.我怎样才能不使用框架来实现这一点。

piece "jsp1":片“jsp1”:

<c:choose>
<c:when test = "${submissionButtonSwitch == 1}">
<div> <!-- div i want to show after -->
<h2>This bill has already been submitted, go back to carry out a new purchase</h2>
</div>
</c:when>
<c:otherwise>
<div class="buttonWrapper"> <!-- div I want to hide after -->
<input class="button" type = "submit" value = "SUBMIT">
</div>
</c:otherwise>
</c:choose>

DIV 按钮

As you can see, I tried to get the result that I want through JSTL server side operations, but after a while I think this has more to do with JavaScript, than any other thing.如您所见,我试图通过 JSTL 服务器端操作获得我想要的结果,但过了一段时间,我认为这与 JavaScript 的关系比其他任何事情都多。 I would be really glad to any suggestion, Im kind of beginner with this.我很乐意接受任何建议,我是这方面的初学者。

Just add load event to check navigation status performance.getEntriesByType("navigation")[0].type === "back_forward" if browser back clicked then show/hide components:只需添加加载事件来检查导航状态performance.getEntriesByType("navigation")[0].type === "back_forward"如果浏览器返回点击然后显示/隐藏组件:

window.addEventListener('load', function(){
    if(performance.getEntriesByType("navigation")[0].type === "back_forward"){
        // show hide components
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM