Solved

Disable events

Posted on 2006-11-20
6
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

734 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