By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,067 Members | 1,818 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,067 IT Pros & Developers. It's quick & easy.

Diable the "Browser Back Button" and send user history back only through my "Back but

P: 1
Hi,
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
  1. <script language="javaScript">
  2. function noBack() {
  3.     window.history.forward();
  4.  
  5.  window.onunload = function() {
  6.     null;
  7. };
  8. setTimeout("noBack()", 0);    
  9. }
  10. </script>
  11. <body onload="noBack();" >

And I could send user history -1 through bellow function.

Expand|Select|Wrap|Line Numbers
  1. <script language="javaScript">
  2. function goBack()
  3.  {
  4.       window.history.go(-1);
  5. }
  6. </script>
  7. <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
  1. <script language="javaScript">
  2. //THIS IS BROWSER HISTORY BACK BLOCK - working fine
  3. var allowBack = false;
  4. function noBack() {
  5.     window.history.forward();
  6.  
  7.  window.onunload = function() {
  8.     null;
  9. };
  10. setTimeout("noBack()", 0);    
  11. }
  12.  
  13. // GO BACK BUTTON FUNCTION
  14. function goBack()
  15.  {
  16.     checkBack2();
  17.     noBack() == false;
  18.     allowBack = true;
  19.       window.history.go(-1);
  20.     return false;
  21. }
  22.  
  23. //BODY ONLOAD CHECK THE FUNCTION WHETHER GO BACK OR STAY THE PAGE
  24. function checkBack2(){
  25.     if(allowBack)
  26.     {
  27.         return goBack();
  28.     }
  29.     else
  30.     {
  31.         return noBack();
  32.     }
  33. }
  34. onclick="return goBack()"
  35. </script>
  36.  
  37. <body onload="checkBack2();" >

Note: We need 2 html files with same javascript to check the function.
So herewith I have attached tow .html files.
Attached Files
File Type: zip back_button.zip (1.5 KB, 55 views)
Jan 8 '14 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
Actually I want to send user history back only through my "Back button".
why?

the back button works perfectly in all browsers.

PS. if my back button were blocked by a webpage script, Id be sure no not come back.
Jan 8 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.