Redirect to another url when back button is clicked using javascript

Jimmy Wales Reply 17:02
you can try this to redirect your own url when clicking browser back button


<script>
jQuery(document).ready(function($) {

      if (window.history && window.history.pushState) {

        $(window).on('popstate', function() {
          var hashLocation = location.hash;
          var hashSplit = hashLocation.split("#!/");
          var hashName = hashSplit[1];

          if (hashName !== '') {
            var hash = window.location.hash;
            if (hash === '') {
              alert('Back button was pressed.');
                window.location='www.yourweburlhere.com';
                return false;
            }
          }
        });

        window.history.pushState('forward', null, './#forward');
      }

    });
</script>

Form validation of numeric characters

Jimmy Wales Reply 15:20
You need to test for the negation of the Regular Expressions because you want the validation to alert upon failure,

(is_valid = !/^[0-9]+$/.test(x))
Example :-

<form action="" method="POST" name="cdp_form" id="cdp_form">
<input type="text" id="phone_number" name="phone_number" placeholder="Enter your phone number" maxlength="10" onkeyup="validateForm()">
<button type="submit" name="SEND" class="btn btn-brown">Send</button>
</form>
<?php echo $successmsg; ?>
<script>
//form validation
function validateForm()
{
var x=document.forms["cdp_form"]["phone_number"].value
if (x==null || x=="")
  {
  alert("Phone number  field must be filled in");
  cdp_form.phone_number.focus();
  return false;
  }
else if (is_valid = !/^[0-9]+$/.test(x))
    {
    alert("Phone number field must have numeric characters");
    cdp_form.phone_number.focus();
    return false;
  }
}
</script>
Copyright by GhostPHP. Powered by Blogger.

Search

Recent Post

Popular Posts

Follow us