Javascript 如何禁用backbutton浏览器

Javascript 如何禁用backbutton浏览器,javascript,reactjs,Javascript,Reactjs,有人能帮我禁用back browser功能需要哪些代码吗? 我想禁用它,因为当用户使用它时,它会重置所有用户条目并从头开始返回。我非常感激你的帮助 下面是我正在使用的代码示例 多谢各位 startTextHandler = async ()=>{ await this.props.form.validateFields(); let takerdetail = this.props.form.getFieldsValue(); let uuid = window.l

有人能帮我禁用back browser功能需要哪些代码吗? 我想禁用它,因为当用户使用它时,它会重置所有用户条目并从头开始返回。我非常感激你的帮助

下面是我正在使用的代码示例

多谢各位

startTextHandler = async ()=>{
    await this.props.form.validateFields();
    let takerdetail = this.props.form.getFieldsValue();
    let uuid = window.location.pathname.split('/').slice(-1)[0];
    const params = {uuid:this.getUUID()};
    axios.get(`${env.url}/api/v1/test/validate-request`,{params}).then((res) => {
        if(res.data.success && (res.data.request.user === takerdetail.email || res.data.request.test_taker === null)){
        takerdetail.sponsor = res.data.request.sponsor;
        takerdetail.uuid = this.getUUID();
        console.log(takerdetail.uuid);
        this.props.dispatch(QuestionActions.setTakerDetail(takerdetail));
        this.props.history.push(`${this.props.location.pathname}/questions`.replace('//','/'));
        }
        else{
            this.props.form.validateFields((error, values) => {
                if (!error) {
                    this.props.form.setFields({
                        email: {
                            value: values.email,
                            errors: [new Error('Wrong email-id or test link')],
                        }
                    });
                } 
                else {
                  console.log('error', error, values);
                }
              });
        }

    }, (err) => {
        this.props.history.push('/');
    });

};
getUUID(){
    return window.location.pathname.match(/([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})/g)[0];
}
    render() {
        const { getFieldDecorator } = this.props.form;

        return (

                                            <div className="subtext">
                                              <Checkbox> I have read and I accept the
                                                  <a target="_blank" href="https://docs.wixstatic.com/ugd/3c785b_bbea80070bda4759bd96f7955b0ef891.pdf"> Terms of Use and Privacy Policy. </a>
                                                I agree that my participation in this personality profiling is voluntary and understand that
                                                my responses will be kept for the intended purposes.</Checkbox>
                                            </div>
                                        )}
                                    </Form.Item>
                                </div>
                                <div className="inputitems terms">

                                    <Form.Item>
                                        {/* <button onClick={this.startTextHandler} className="psButton">START THE TEST</button> */}
                                        <Button  onClick={this.startTextHandler} text={"START THE TEST"}/>
                                    </Form.Item>
                                </div>
                            </Form>
                        </div>
                    </div>
                </div>
            </div>
        )

    }
}
export default  connect()(withRouter(Form.create({ name: 'register' })(TakerDetail)));
startTextHandler=async()=>{
等待这个.props.form.validateFields();
让takerdetail=this.props.form.getFieldsValue();
让uuid=window.location.pathname.split('/').slice(-1)[0];
常量参数={uuid:this.getUUID()};
get(`${env.url}/api/v1/test/validate request`,{params})。然后((res)=>{
if(res.data.success&(res.data.request.user==takerdetail.email | | res.data.request.test_taker==null)){
takerdetail.sandor=res.data.request.sandor;
takerdetail.uuid=this.getUUID();
console.log(takerdetail.uuid);
this.props.dispatch(QuestionActions.setTakerDetail(takerdetail));
this.props.history.push(`this.props.location.pathname}/questions`.replace('/','/');
}
否则{
this.props.form.validateFields((错误,值)=>{
如果(!错误){
this.props.form.setFields({
电邮:{
value:values.email,
错误:[新错误('错误的电子邮件id或测试链接')],
}
});
} 
否则{
日志('error',error,value);
}
});
}
},(错误)=>{
this.props.history.push('/');
});
};
getUUID(){
返回window.location.pathname.match(/([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})/g)[0];
}
render(){
const{getFieldDecorator}=this.props.form;
返回(
我已阅读并接受
我同意我参与这一人格特征分析是自愿的,并理解这一点
我的答复将按预期目的保留。
)}
{/*开始测试*/}
)
}
}
导出默认连接()(withRouter(Form.create({name:'register'})(TakerDetail));

通常,您不应禁用浏览器中的“后退”按钮

也就是说,当用户输入数据时,您可以使用浏览器状态来创建一个新的状态,以便在用户按下后退按钮时可以将数据弹出回浏览器,从而实现您的目标


这里解释了如何操作浏览器历史记录并向历史记录中添加状态,以便用户可以备份(例如)他们以前在页面上输入的内容。(您只需在代码中创建允许该操作的机制即可。)

通常,您不应禁用浏览器中的“后退”按钮

也就是说,当用户输入数据时,您可以使用浏览器状态来创建一个新的状态,以便在用户按下后退按钮时可以将数据弹出回浏览器,从而实现您的目标


这里解释了如何操作浏览器历史记录并向历史记录中添加状态,以便用户可以备份(例如)他们以前在页面上输入的内容。(您只需在代码中创建允许此操作的机制即可。)

过去三天我一直在解决此问题。 您不能禁用浏览器后退按钮
你会发现很多方法,比如删除历史等等

过去三天来,我一直在研究这个问题。 您不能禁用浏览器后退按钮
你会发现很多方法,比如删除历史等等

您无法真正更改网页所在视口之外的任何操作-即,谢天谢地,“后退”按钮不在您的控制之下-也许您需要先修复您的网页,我认为这将对您有所帮助。您无法真正更改网页所在视口之外的任何操作-即,谢天谢地,“后退”按钮不在您的控制之下-也许您需要先修复您的网页,我认为这将对您有所帮助。