JS设置页面无法回退

JS设置防止页面回退

登录页面

<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2020/8/27
  Time: 14:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>公寓管理系统 - 登录页面</title>
    <link rel="stylesheet" href="css/index.css">
</head>
<body>
    <div class="login">
        <img src="image/logo.png" alt="智游">
        <p>公寓管理系统</p>
        <form action="<c:url value = "/login.action"/>" method="post">
            <div>
                <input type="text" id="username" name="wname" value="" placeholder="请输入用户名">
            </div>
            <div>
                <input type="password" id="password" name="wpwd" value="" placeholder="请输入密码">
            </div>
            <c:if test="${not empty login_message}">
                <p class="error-message">${login_message}</p>
            </c:if>
            <div><input type="submit" value="登录" class="input_submit"></div>
        </form>
    </div>
</body>
<script>
    if (window.top !== window) {
        window.top.location.reload();
    }
</script>
</html>

在script标签中加上


    history.pushState(null, null, document.URL);
    window.addEventListener('popstate', function () {
        history.pushState(null, null, document.URL);
    });

如下图所示:

<script>
    if (window.top !== window) {
        window.top.location.reload();
    }
    history.pushState(null, null, document.URL);
    window.addEventListener('popstate', function () {
        history.pushState(null, null, document.URL);
    });
</script>

将上方代码写到head和body的中间,因为它是从上到下依次执行,在下方的话,它运行需要时间。

<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2020/8/27
  Time: 14:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>公寓管理系统 - 登录页面</title>
    <link rel="stylesheet" href="css/index.css">
</head>
<script>
    if (window.top !== window) {
        window.top.location.reload();
    }
    history.pushState(null, null, document.URL);
    window.addEventListener('popstate', function () {
        history.pushState(null, null, document.URL);
    });
</script>
<body>
    <div class="login">
        <img src="image/logo.png" alt="智游">
        <p>公寓管理系统</p>
        <form action="<c:url value = "/login.action"/>" method="post">
            <div>
                <input type="text" id="username" name="wname" value="" placeholder="请输入用户名">
            </div>
            <div>
                <input type="password" id="password" name="wpwd" value="" placeholder="请输入密码">
            </div>
            <c:if test="${not empty login_message}">
                <p class="error-message">${login_message}</p>
            </c:if>
            <div><input type="submit" value="登录" class="input_submit"></div>
        </form>
    </div>
</body>
</html>

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值