Tuesday 4 August 2015

JQuery Back button [Go to previous page]

For Go to previous page use following method

parent.history.back();

[OR]

document.referrer;

A.html

<html>
<body>
From Page A
<a href="C.html">Next</a>
</body>
</html>

B.html

<html>
<body>
From Page B
<a href="C.html">Next</a>
</body>
</html>

C.html

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>

$(document).ready(function(){
   $("#back").click(function() {
parent.history.back();
});
});


 /* $(document).ready(function(){
   $("#back").click(function() {
   var previousPage =  document.referrer;
window.location.href = previousPage;
});

}); */

</script>
</head>
<body>
From Page C ...
<button id="back">Back</button>
</body>
</html>

No comments:

Post a Comment