Solved

Disable events

Posted on 2006-11-20
6
228 Views
Last Modified: 2011-08-18
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
Comment
Question by:basirana
6 Comments
 
LVL 17

Expert Comment

by:gops1
ID: 17980255
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17980357
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
 

Author Comment

by:basirana
ID: 17981299
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 17

Expert Comment

by:gops1
ID: 17981347
Expire your cache that is the best thing you can do to avoid back and forward
0
 
LVL 23

Accepted Solution

by:
rama_krishna580 earned 500 total points
ID: 17981574
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17981883
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now