Welcome to WebmasterWorld Guest from 50.19.53.104

Forum Moderators: open

Message Too Old, No Replies

Right Click Protection

using JavaScript for IE

     

joshie76

12:17 pm on Feb 6, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does anybody know of a script where when you right click on a document nothing happens. Normally you would get the Right Click menu with 'View Source' etc and the following script prevents it by showing an alert instead (IE only).

<script>
function rightClick()
{
if (event.button == 2 event.button == 3 event.keyCode == 93)
{
alert("Some message");
return false;
}
return true;
}

document.onmousedown=rightClick;
document.onmouseup=rightClick;
document.onkeydown=rightClick;
</script>

Ideally though I'd like to prevent access to the right menu but just have nothing happen instead of the alert - I can't seem to get it to work though. I only need this for IE5+, any ideas anybody?

I know these scripts are far from fool proof... but we like the idea of making things just that tiny bit more difficult;)

txbakers

1:29 pm on Feb 6, 2002 (gmt 0)

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Hey Joshie:

The no Right Click is a gimmick at best and an annoyance at worst.

Even web users witha little savvy can go to the View Menu to view source.

What I've seen (and I can't find it now that I'm looking for it!) is a view source that would have about 60 blank lines at the top of the source code, so it looks like the "source" is blank. Of course if someone were to scroll down they'd see the code.

I'm resigned to having my code looked at. That's what I like about server side ASP and such - that gets hidden.

Ove

1:37 pm on Feb 6, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



check your sticky

/Ove

joshie76

1:39 pm on Feb 6, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmph, The reasons are complicated: In truth, one of the main reason we've disabled the right menu is that the application we're developing has required us to remove the browser controls (back/forward/refresh which also feature in the right-click menu*). I will stress now that this is not a web-site we're working on but a web application - we have our reasons, you'll just have to trust me.

Got any ideas on how I can get that right click without popup?

*I'm aware that people can use keyboard shortcuts etc...

gethan

2:05 pm on Feb 6, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Joshie - first - some moral support, I too have written apps (not sites) that have disabled back and forward browser navigation. Signup wizards and the like. Popup new window - and do a series of steps ... lots of work to keep checking if a particular event has already happened and what the user is expecting to see.

It is possible to get round all of this with some complicated page and session management code but often the additional effort isn't justified.

Now for something hopefully more useful ;)

[javascript.internet.com...]

Works for IE, Netscape (<6). But won't work for Opera, Mozilla etc etc.

joshie76

10:03 am on Mar 4, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cracked it...

<body oncontextmenu="return false;">

This stops the popup and you don't have to have an alert (IE Only).

JakeFrederick

11:35 pm on Mar 4, 2002 (gmt 0)

10+ Year Member



I can understand you not wanting someone to plagerise(spelling) your site, but is it really that big of a deal if someone's looking at your source? I know for me when I first started HTML viewing others source codes helped me tremendously. Are there other reasons for not wanting the source to be viewed?

Crazy_Fool

1:05 am on Mar 5, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



disabling right click is a bad move ... don't do it unless you really have to ...
and if you have to, then maybe HTML aint the right way to do what you want ... maybe Flash (as much as i despise it) would be a better solution ...

joshie76

9:23 am on Mar 5, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As I menthioned above, it's for an application - not a website. It's not so much about disabling the view source option as disabling the back option. I wouldn't remove the right menu from an internet facing website.

It's a huge data management application - I don't fancy writing it in Flash!

Brett_Tabke

1:19 pm on Mar 6, 2002 (gmt 0)

WebmasterWorld Administrator brett_tabke is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



The harder the source is to view? The more I want to view it.

joshie76

1:25 pm on Mar 6, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



... and the more aware you'll be that you'll be infringing copyrights if you steal the pictures/code.

txbakers

1:44 pm on Mar 6, 2002 (gmt 0)

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member



If it's a huge data management app, then it must rely on some type of server side coding (ASP/JSP/PHP) and that code - the real meat of your app - is not visible to the user.

Let them see the HTML all they want - it still doesn't reveal the database structure or the SQL commands being used, or your nifty techniques.

joshie76

2:46 pm on Mar 6, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, there is an awful lot of clever code on the client but not that I mind them looking at it (and nothing that would risk security). In this case the right menu was disabled to discourage it being used for back, forward and refresh (too complicated to go into now).

OK - look - I've never used right click protection to stop people from viewing my source. Never, ever.

Though I do think if you have, say, some images that are precious to you and you want to put them on the internet but don't want them ripped off then a little 'reminder' does no harm. This way you don't have to disfigure the image with a watermark and someone taking it is fully aware that you'll be miffed when they do...

txbakers

6:03 pm on Mar 6, 2002 (gmt 0)

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I like the trick of putting an HTML comment at the top of the source page, then inserting 60 or so blank lines before the actual source begins.

Another deterrent to the uninitiated.

Purple Martin

3:50 am on Mar 7, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can understand why people find turning off the right-click menu an annoyance, and it isn't something I'd normally do.

However, there is the occaisional situation where it is an appropriate thing to do. Coincidentally, I've just been working on an assessment application for one of the high-street banks (IE 5.5 only - bliss!). As staff career prospects are linked to their performance in the assesment, it's important to hide answer information from them. Most of this is done by using ASP, but I've still disabled the usual right-click menu for extra security (I'm actually providing a custom menu instead). One other thing - the application is presented in a full-screen chromeless browser window, so there's no View menu available.

nell

6:47 pm on Mar 7, 2002 (gmt 0)

10+ Year Member



Images you don't want copied can be layered over with a tranparent .gif of the same size. Let them right click away and steal the transparent .gif file.

joshie76

9:43 am on Mar 8, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Clever Nell! - that would really throw you for a while wouldn't it!

DrOliver

10:28 am on Mar 8, 2002 (gmt 0)

10+ Year Member



Yes, clever, but not perfect. I haven't seen anything yet that would stop anyone "stealing" your pictures by taking a screenshot of them.

I do understand though that for some occasions there is a need to hide whatever can be taken or seen by using the functions in the context-menu.

joshie76

10:46 am on Mar 8, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you really want to protect your scripts and your audience is IE5+ you can always use the MS Script Encoder:

[msdn.microsoft.com...]

Though this isn't bullet proof either - just an extra level.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month