Link to home
Start Free TrialLog in
Avatar of basirana
basirana

asked on

Disable events

Hi

I have 3 important questions.

1. How to disable back button in the browser? User should not go back by clicking back button in the browser.
2. How to disable view source in the browser?
3. how to disable disable mouse right click?

Please help me with sample code.

Thanks
Avatar of gops1
gops1
Flag of United States of America image

Point 1 & 2. You cannot

For 3 try this code:

<html>
      <head>
            <title>Script Demo</title>
            <script language="JavaScript">
                  <!--
                        function inIE(){
                              if (event.button==2){
                                    return false;
                              }
                        }

                        function inNS(e){
                              if (document.layers||document.getElementById&&!document.all){
                                    if (e.which==2||e.which==3){
                                          return false;
                                    }
                              }
                        }

                        if (document.layers){
                              document.captureEvents(Event.MOUSEDOWN);
                              document.onmousedown=inNS;
                        }
                        else if (document.all&&!document.getElementById){
                              document.onmousedown=inIE;
                        }

                        document.oncontextmenu=new Function("return false")

                  // -->
            </script>
      </head>
<body>
</body>
</html>
Avatar of Michel Plungjan
More to the point: If the page is on the internet, you can do NOTHING to stop it from being saved, viewed, copied.

I can turn off javascript
I can view generated html in Firefox
I can look in my cache
I can do view-source:http://yoursite.com/yourpage.html or just use a plugin for firefox to do it for me

You may want to tell us what you are trying to achieve instead of trying to block people from seeing your site.
<a href="page.html" onClick="location.replace(this.href); return false">Replace current page</a>
will for example show a new page and not disable the back button but simply remove the page from history.
this is again possible to bypass by turning JS off.

Michel
Avatar of basirana
basirana

ASKER

I want to create a secure code so that the parameter names... they should be able to navigate forward but the back should be deabled.
There are some hidden parameters they should not be seen by users.
I want to implement some sort of security to my page.

Thanks
Expire your cache that is the best thing you can do to avoid back and forward
ASKER CERTIFIED SOLUTION
Avatar of rama_krishna580
rama_krishna580
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
please never use the onLoad=history code since it BREAKS the back button instead of disable the previous page. location.replace is much gentler and more effective. to hide data, encrypt it instead. if it is important enough, people WILL decrypt it though.