• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

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
0
basirana
Asked:
basirana
1 Solution
 
gops1Commented:
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>
0
 
Michel PlungjanIT ExpertCommented:
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
0
 
basiranaAuthor Commented:
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gops1Commented:
Expire your cache that is the best thing you can do to avoid back and forward
0
 
rama_krishna580Commented:
Hi,

1. <body onLoad="history.go(+1)"> put it on the page where you dont want it to Go.
2. There are a number of ways to accomplish the blocking of right mouse clicks such that your source HTML can not be copied.  These are browser specific.  I have found no way to block the viewing of HTML that works across Microsoft Internet Explorer, Netscape Navigator, Mozilla, and Opera.

Recall that back when the World Wide Web was ARPnet openness was encouraged.  What you can do is to make it more difficult by running your JavaScripts from a file.  I run HomeSite 5.0 and can quite easily pull such scripts right into this HTML editor.  So even running JavaScript from a file is not fully secure from theft.
Short and sweet; there is no way to do what you wish to do.

3.
http://javascript.internet.com/page-details/no-right-click.html
http://website-design.anandsoft.com/free-scripts/disable-right-mouse-click.html
<HEAD>

<SCRIPT LANGUAGE="JavaScript1.1">
<!-- Original:  Martin Webb (martin@irt.org) -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function right(e) {
if (navigator.appName == 'Netscape' && 
(e.which == 3 || e.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' && 
(event.button == 2 || event.button == 3)) {
alert("Sorry, you do not have permission to right click.");
return false;
}
return true;
}

document.onmousedown=right;
document.onmouseup=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown=right;
window.onmouseup=right;
//  End -->
</script>
</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document  -->

<BODY>

<center>[ Try right-clicking the image and then the text link below ]

R.K

0
 
Michel PlungjanIT ExpertCommented:
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now