My requirment is diable the "Browser Back Button" and create "Back Button" to go History -1.
Actually I want to send user history back only through my "Back button".
I could disable "Browser Back Button"
Expand|Select|Wrap|Line Numbers
- <script language="javaScript">
- function noBack() {
- window.history.forward();
- window.onunload = function() {
- null;
- };
- setTimeout("noBack()", 0);
- }
- </script>
- <body onload="noBack();" >
And I could send user history -1 through bellow function.
Expand|Select|Wrap|Line Numbers
- <script language="javaScript">
- function goBack()
- {
- window.history.go(-1);
- }
- </script>
- <input type="button" onclick="goBack()" value="Go Back" />
My Problem is function goBack() will be disable because of function noBack().
Now I need to run function goBack() and stop noBack() when I click the button.
So I write condition like bellow. It doesn't work.
Expand|Select|Wrap|Line Numbers
- <script language="javaScript">
- //THIS IS BROWSER HISTORY BACK BLOCK - working fine
- var allowBack = false;
- function noBack() {
- window.history.forward();
- window.onunload = function() {
- null;
- };
- setTimeout("noBack()", 0);
- }
- // GO BACK BUTTON FUNCTION
- function goBack()
- {
- checkBack2();
- noBack() == false;
- allowBack = true;
- window.history.go(-1);
- return false;
- }
- //BODY ONLOAD CHECK THE FUNCTION WHETHER GO BACK OR STAY THE PAGE
- function checkBack2(){
- if(allowBack)
- {
- return goBack();
- }
- else
- {
- return noBack();
- }
- }
- onclick="return goBack()"
- </script>
- <body onload="checkBack2();" >
Note: We need 2 html files with same javascript to check the function.
So herewith I have attached tow .html files.