Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. javascript for disable back button

javascript for disable back button

Scheduled Pinned Locked Moved ASP.NET
javascripthtmltutorialquestion
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kissy16
    wrote on last edited by
    #1

    hai all, am adding the following code in html for disabling the back button. but am need to call this function on pageload? If to call,how to do that? Am just added in html and tested but its not working. Please let me know if any of u know the solution My code is here function StopBackward() { window.history.back(-1); }

    kissy

    C J B R 4 Replies Last reply
    0
    • K Kissy16

      hai all, am adding the following code in html for disabling the back button. but am need to call this function on pageload? If to call,how to do that? Am just added in html and tested but its not working. Please let me know if any of u know the solution My code is here function StopBackward() { window.history.back(-1); }

      kissy

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You're living in a fantasy. You can't stop the user going back. Instead, you should fix your overall design.

      Christian Graus Driven to the arms of OSX by Vista. Please read this[^] if you don't like the answer I gave to your question. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.

      1 Reply Last reply
      0
      • K Kissy16

        hai all, am adding the following code in html for disabling the back button. but am need to call this function on pageload? If to call,how to do that? Am just added in html and tested but its not working. Please let me know if any of u know the solution My code is here function StopBackward() { window.history.back(-1); }

        kissy

        J Offline
        J Offline
        Jay Royall
        wrote on last edited by
        #3

        For what reason do you want to disable the back button? Many, including myself, use the back button often and I would consider it to be a usability issue if I couldn't go back a page easily.

        K 1 Reply Last reply
        0
        • J Jay Royall

          For what reason do you want to disable the back button? Many, including myself, use the back button often and I would consider it to be a usability issue if I couldn't go back a page easily.

          K Offline
          K Offline
          Kissy16
          wrote on last edited by
          #4

          thanks for ur answers. Ex:If menu contains, page1 page2 page3 and logout page. after login,he can go to page2 and page1 with back button,but from page1 he should not go to login page with browsers.With logout only he can go back to login page. once user login,and reached main menu page,until unless he clicked on the logout,he should not go back to the login page by clicking on the browers back button. This is my requirement.Please let me know if any one of u understand and had solution.

          kissy

          J C 2 Replies Last reply
          0
          • K Kissy16

            thanks for ur answers. Ex:If menu contains, page1 page2 page3 and logout page. after login,he can go to page2 and page1 with back button,but from page1 he should not go to login page with browsers.With logout only he can go back to login page. once user login,and reached main menu page,until unless he clicked on the logout,he should not go back to the login page by clicking on the browers back button. This is my requirement.Please let me know if any one of u understand and had solution.

            kissy

            J Offline
            J Offline
            Jay Royall
            wrote on last edited by
            #5

            Just as long as the page isn't cached then you can handle what to do in the one of the page events (not sure of the best one, maybe page_load?). That is, if the user is logged in and he/she tries to go back to the login page then hide the login form and maybe show a message saying 'Already Logged In' or something. If the user has logged out and he/she tries to go back to a secured page then re-direct to the login page. I think you can set whether to cache the page or not using the Response object.

            1 Reply Last reply
            0
            • K Kissy16

              thanks for ur answers. Ex:If menu contains, page1 page2 page3 and logout page. after login,he can go to page2 and page1 with back button,but from page1 he should not go to login page with browsers.With logout only he can go back to login page. once user login,and reached main menu page,until unless he clicked on the logout,he should not go back to the login page by clicking on the browers back button. This is my requirement.Please let me know if any one of u understand and had solution.

              kissy

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Like I said, if you fix your site, then you will solve your problem. Write good code, don't try to hack your way through bad code.

              Christian Graus Driven to the arms of OSX by Vista. Please read this[^] if you don't like the answer I gave to your question. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.

              K 1 Reply Last reply
              0
              • C Christian Graus

                Like I said, if you fix your site, then you will solve your problem. Write good code, don't try to hack your way through bad code.

                Christian Graus Driven to the arms of OSX by Vista. Please read this[^] if you don't like the answer I gave to your question. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.

                K Offline
                K Offline
                Kissy16
                wrote on last edited by
                #7

                thanks for ur answer,but i dont understand ur idea. how to fix the design. What exactly i have to do. I think u got my question and please try to explain me correctly. please it is my request.

                kissy

                1 Reply Last reply
                0
                • K Kissy16

                  hai all, am adding the following code in html for disabling the back button. but am need to call this function on pageload? If to call,how to do that? Am just added in html and tested but its not working. Please let me know if any of u know the solution My code is here function StopBackward() { window.history.back(-1); }

                  kissy

                  B Offline
                  B Offline
                  Brian W King
                  wrote on last edited by
                  #8

                  Try this out; protected void Page_load { StringBuilder javaScript = new StringBuilder(); javaScript.Append("\n<script language=JavaScript>\n"); javaScript.Append("window.history.forward(1);\n"); javaScript.Append("</script>\n"); Page.RegisterClientScriptBlock("HistoryScript", javaScript.ToString()); } Its a bit of a trick, but works for me. The real problem is that newer browsers purposefully remove the ability for code to effect the menus of the browser now as some nasty hackers keep finding ways to hijack the browser using these methods. Probably the code above will become useless after a time too when someone starts to use it in-appropriately and we will have to creatively come up with a new method. Just be cautious in how you apply it. :cool:

                  1 Reply Last reply
                  0
                  • K Kissy16

                    hai all, am adding the following code in html for disabling the back button. but am need to call this function on pageload? If to call,how to do that? Am just added in html and tested but its not working. Please let me know if any of u know the solution My code is here function StopBackward() { window.history.back(-1); }

                    kissy

                    R Offline
                    R Offline
                    RichardGrimmer
                    wrote on last edited by
                    #9

                    For GOD'S sake abandon the way you're doing it. Many MANY people post similar questions, and the answer's always the same. If you NEED to disable standard controls in the browser for your site to work, you've designed it WRONGLY. Not sure I understand what you're asking, but I suspect that it's that you don't want users to redirect to a login page they've already completed - if that's the case, look at Forms authentication in MSDN...but please PLEASE don't start hacking the browser just to make things work - it's not only really silly, but it also gives others the idea that it's OK!

                    C# has already designed away most of the tedium of C++.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups