Show form after click back button

三世轮回 提交于 2019-12-11 04:36:14

问题


I use jquery to show hidden form. I want to know how I can automatically show form when user click Submit and then press back button. I don't want user to click New Account again to show form after they click back button.

I have these working code currently:

<head>
    <script src="https://code.jquery.com/jquery-latest.js">
    </script>
    <script type="text/javascript">
     $(function() {
     $('#register_link').click(function() {
         $('#show_form').toggle();
         return false;
     });
 });
    </script>
</head>
<a href="http://www.google.com/">Google</a>
&nbsp;|&nbsp;
<a href="#" id="register_link">New Account</a>
<div id="show_form" style="display: none;">
    <form id="register_form" method="post" action="verify.php">
        Username
        <inputname="username" id="username" type="text">
            <br>
            Email
            <input name="email" id="email" type="email">
            <br>
            <input class="button_register" type="submit" value="Create New Account"
            />
    </form>
</div>

Example: http://jsfiddle.net/n9uGH/17/

Is it actually possible? Thanks in advance


回答1:


There are various ways that this could be achieved, however this depends on your server-side language and or hosting environment. Here is a fairly simple widely accepted methodology that should serve your purpose.

This is based on this cookie library for jQuery https://github.com/carhartl/jquery-cookie

Using cookies you can persist the information between the two page loads.

So on your form page you would do something like this

$(function() {
    $('#register_link').click(function() {
        $('#show_form').toggle();
        return false;
    });
    if($.cookie('form_submitted')){
        $('#show_form').toggle();
    }
});

Then on the page which appears after submitting the form you can do this

$(function() {
    $.cookie('form_submitted', 'yes');
});


来源:https://stackoverflow.com/questions/18687252/show-form-after-click-back-button

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!