简体   繁体   English

如何禁用后退按钮浏览器

[英]How to disable backbutton browser

could someone please help me what codes I need to disable the back browser function?有人可以帮我禁用后台浏览器功能需要什么代码吗? I want to disable it because when the user uses it, it resets all user entry and gets back from the beginning beginning.我想禁用它,因为当用户使用它时,它会重置所有用户条目并从头开始返回。 I am very noob so your help would be greatly appreciated.我很菜鸟,所以你的帮助将不胜感激。

Here's just sample of the codes I am using这只是我正在使用的代码示例

Thank you very much!非常感谢!

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)));

As a rule, you should not be disabling the back button in the browser.通常,您不应禁用浏览器中的后退按钮。

That said, you can probably achieve your goal by using the browser state as intended to create a new state when the user inputs data so that it can be popped back into the browser when the user pushes the back button.也就是说,您可能可以通过使用浏览器状态来实现您的目标,以便在用户输入数据时创建新状态,以便在用户按下后退按钮时将其弹回浏览器。

https://www.sitepoint.com/javascript-history-pushstate/ https://www.sitepoint.com/javascript-history-pushstate/

There's an explanation of how to manipulate browser history and add states to the history so that the user can back up to (for example) what they had previously entered on your page.有关于如何操纵浏览器历史记录并向历史记录添加状态的说明,以便用户可以备份(例如)他们之前在您的页面上输入的内容。 (You just have to create the mechanism that allows for that in your code.) (你只需要在你的代码中创建允许这样做的机制。)

I have been working on this problem from last three days.从过去三天我一直在研究这个问题。 You cannot disable the browser back Button You will find many methods like erasing the history and so on.您无法禁用浏览器后退按钮您会发现许多方法,例如删除历史记录等。

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

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