Solved

Disable events

Posted on 2006-11-20
6
226 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

762 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

18 Experts available now in Live!

Get 1:1 Help Now