473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Preventing user from copy/paste option

Hi,

I have a text box and should allow user to type the text but not to allow them to copy/paste or right click.

Here is the code.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  4. <title>Untitled Document</title>
  5. <script language="javascript">
  6. function whichButton(event)
  7. {
  8. if (event.button==2)//RIGHT CLICK
  9. {
  10. alert("Not Allow Right Click!");
  11. }
  12.  
  13. }
  14. function noCTRL(e)
  15. {
  16. var code = (document.all) ? event.keyCode:e.which;
  17.  
  18. var msg = "Sorry, this functionality is disabled.";
  19. if (parseInt(code)==17) //CTRL
  20. {
  21. alert(msg);
  22. window.event.returnValue = false;
  23. }
  24. }
  25. </script>
  26. </head>
  27. <body>
  28. <form method="">
  29. <strong>Not Allow Paste </strong><BR>
  30. <input type="text" value="" onMouseDown="whichButton(event)" onKeyDown="return noCTRL(event)"/>
  31. </form>
  32. </body>
  33. </html>
  34.  
It works properly in IE and in mozilla also but in mozilla when right click option is used it will display the message saying that "Not allow right click option" but the menu will also displayed (i.e cut,copy,select all) and it allows to paste also.

How can this be avoided?

Any suggestions!!

with regards
Archana
Oct 13 '08 #1
18 9583
acoder
16,027 Expert Mod 8TB
The first question to ask yourself is why you need this.

Rarely is it a good idea. In fact, some browsers allow users to prevent JavaScript code itself from preventing certain expected browser functionality.
Oct 13 '08 #2
The first question to ask yourself is why you need this.

Rarely is it a good idea. In fact, some browsers allow users to prevent JavaScript code itself from preventing certain expected browser functionality.
Hi,

I need this because we are using email option so i want user to type there email id .They should not copy/paste there id's they should only type it. For that reason i should solve this problem!!

Any idea???

with regards
Archana
Oct 13 '08 #3
rnd me
427 Expert 256MB
human typing vastly increases the chance for error.
the form take longer to fill out.
these types of restrictions can make the page less accessible to disabled users.
doing so will also anger a large chuck of regular users.
it also does nothing to penalize someone who has javascript disabled, how fair is that?

what in your script prevents <shift>+<insert> or a menu key from pasting it in?

i beg you to ask yourself why you are going down this path in the first place.
clicking 'submit' can create a legally binding contract.

there is not a good enough reason to do so.
Oct 13 '08 #4
acoder
16,027 Expert Mod 8TB
If it's for just a second confirmatory email field, this thread may help (if you insist).
Oct 13 '08 #5
human typing vastly increases the chance for error.
the form take longer to fill out.
these types of restrictions can make the page less accessible to disabled users.
doing so will also anger a large chuck of regular users.
it also does nothing to penalize someone who has javascript disabled, how fair is that?

what in your script prevents <shift>+<insert> or a menu key from pasting it in?

i beg you to ask yourself why you are going down this path in the first place.
clicking 'submit' can create a legally binding contract.

there is not a good enough reason to do so.
Hi,

Thanks for your reply!!!

With regards
Archana
Oct 14 '08 #6
If it's for just a second confirmatory email field, this thread may help (if you insist).
Hi,

Ya sure i will look into that!!!

Thanks for your reply!!!

With regards
Archana
Oct 14 '08 #7
Both of my senior friends are correct but that is what the buisness concern.If someone wants to disable the right click not for the text field but for the pictures then the logic what my seniors has given is not correct.

This is about the technical concept what we are dealing .Right now for Archanak she wants to do it for the text field and she is getting some problem wth the mozila explorer so instead of talking about the business we should tell her about why the problem is.Isn't it my friends?

So, technically if you want to disable the right click of the mouse for the whole document then oncontextmenu is helpful.
But for the different tags you can't use this .So what you had done is ok with IE.

For mozila Add this piece of code where e is the event.As Mozila does not behave same as IE in context of script handling.
Expand|Select|Wrap|Line Numbers
  1. function ffdisable(e)
  2. {
  3. if (e.button==2)
  4.   { //firefox disable
  5.   e.preventDefault();
  6.   e.stopPropagation();
  7.   alert(message);
  8.   return false;
  9.   }
  10. }
Oct 14 '08 #8
acoder
16,027 Expert Mod 8TB
Not quite. I understood what Achana asked. Pictures don't make a difference because the logic is inherently flawed. Trying to prevent the user from copy/pasting creates more problems than it solves unless you have some form of control over the user base, you use it sparingly and wisely and there are no accessibility problems. So explaining why it's not working in a particular browser is probably not required in most cases.
Oct 14 '08 #9
Yes acoder that is fine but if that is requirement then we sholuld explain why the thing is malfunctioning.Thats what I had told there might be any other case also where people need not the copy/paste option but they want to disable the right click as per the code pasted by Archana.

Archana's code as she explained is running in IE but not in Mozila.So I had told to focus on this.Nothing else then that

What you suggested that is much fine.But my attention was to focus the problem as she mentioned.Please dont mind this otherwise.
Oct 14 '08 #10
Both of my senior friends are correct but that is what the buisness concern.If someone wants to disable the right click not for the text field but for the pictures then the logic what my seniors has given is not correct.

This is about the technical concept what we are dealing .Right now for Archanak she wants to do it for the text field and she is getting some problem wth the mozila explorer so instead of talking about the business we should tell her about why the problem is.Isn't it my friends?

So, technically if you want to disable the right click of the mouse for the whole document then oncontextmenu is helpful.
But for the different tags you can't use this .So what you had done is ok with IE.

For mozila Add this piece of code where e is the event.As Mozila does not behave same as IE in context of script handling.
Expand|Select|Wrap|Line Numbers
  1. function ffdisable(e)
  2. {
  3. if (e.button==2)
  4.   { //firefox disable
  5.   e.preventDefault();
  6.   e.stopPropagation();
  7.   alert(message);
  8.   return false;
  9.   }
  10. }
Hi ,

Thanks for your reply!!!!
I tried but its giving that message("No right click is allowed) and along with that (cut,copy,paste,selectall) option menu is also displayed.

There is no solution for this problem?
with regards
Archana
Oct 14 '08 #11
acoder
16,027 Expert Mod 8TB
There is, but you're going about it in the wrong way. Have you tried the code in the thread I linked to earlier?
Oct 14 '08 #12
There is, but you're going about it in the wrong way. Have you tried the code in the thread I linked to earlier?
Hi,

I tried!!!

But i am getting context menu(cut,copy,paste)

I don't want context menu to come!!!

I have only one text box to take email id.

How should i call this function?

with regards
Archana
Oct 15 '08 #13
acoder
16,027 Expert Mod 8TB
The code won't prevent the context menu from appearing because it doesn't need to. It detects a paste and lets the user know that the second email has to be typed in. Surely, that's what you wanted? It has the advantage of keeping all the browser functionality and still meeting your requirements.
Oct 15 '08 #14
The code won't prevent the context menu from appearing because it doesn't need to. It detects a paste and lets the user know that the second email has to be typed in. Surely, that's what you wanted? It has the advantage of keeping all the browser functionality and still meeting your requirements.
Hi,

Is it possible to do such that context menu should not appear or even paste option should not be highlighted?

It works fine in IE i.e context menu will not appear in IE. but context menu appears in firefox.

How to avoid that??

With regards
Archana
Oct 16 '08 #15
acoder
16,027 Expert Mod 8TB
OK, let's say you manage to disable the context menu in Firefox, but what about a user using the keyboard or using a scriptlet to automatically copy/paste the value? What if someone wants to use the context menu for another part of your page? What about the options from the file menu? What about other browsers? What about users who disable the ability of scripts interfering with functions like this? What about disabled users? Wat about someone who's disabled JavaScript? and so on...

By using the script suggested (in the link), the user can paste content as normal but it will be detected if it's not a single character key press. Anyone who works around that, well, you can always offer a change email page.
Oct 16 '08 #16
eshka
2
It works perfectly!

Expand|Select|Wrap|Line Numbers
  1. <input type="text" onkeydown="checkItNoPaste(event);" />
Expand|Select|Wrap|Line Numbers
  1. function checkItNoPaste(evt){
  2.    evt = (evt) ? evt : window.event;
  3.    input= evt.target || evt.srcElement;
  4.    input.setAttribute('maxlength', input.value.length + 1); 
  5. }
So if user tries to paste using Ctrl+V or Ctrl+Insert, it pastes only 1 symbol.
And it's impossible to paste using context menu.
Nov 13 '08 #17
Hello Everybody,

I am havig the same problem but not with textbox but with address bar.
Can anyone help me out

Thanks,
Sri Praveen
Apr 28 '09 #18
Markus
6,050 Expert 4TB
@sripraveen
You have no control over the browser (from the webpage), nor should you be able to.

Why shouldn't the user be able to copy/paste in the address bar? You can't _force_ them to stay on your webpage. Is it really that bad? ;)

Mark.
Apr 28 '09 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Rafal Rutkowski | last post by:
Hi, Does anyone know a way to prevent IE from selecting text when a user clicks the text while holding shift/ctrl key? -- Rudy
4
by: Mike Surrett | last post by:
Is there a way to change the copy/paste setting in VS.net 2003 so that when you paste it will paste at the current location and not to the upper left hand corner. -- MIke
1
by: Sean Howard | last post by:
Dear All, As is my want I need to do something in Access that seems simple but cannot fathom out. I have main form with two subforms, both datasheets with an almost identical table structure....
5
by: Kaur | last post by:
Hi, I have been successful copying a vba code from one of your posts on how to copy and paste a record by declaring the desired fields that needs to be copied in form's declaration and creating two...
17
by: emma.sax | last post by:
Hi all, I have a form where we would like the user to input their email address twice, to ensure they've typed it correctly, as is found on most sign-ups I'm looking for a solution to the...
6
by: garyusenet | last post by:
Hi I would like to know if it's possible to copy just the collapsed view vissible from the IDE to the clipboard. If i have collapsed code, and then highlight it and copy it - and then paste this...
6
by: rakeshvthu | last post by:
hi all, can we disable the copy and paste option in edit menu bar of browser my customer does not want copying using any technique so can any one help how to disable that options copy and...
3
by: divyasrinivasan | last post by:
hi all question is :wen i copy any text and try to paste it in the web form it shlould not paste..i can disable rt click but tats not the requiremnet..i want to copy the text but there should not...
3
by: questionit | last post by:
Some websites disable the Windows copy and paste feature to use on thier website. A text can not be copied and pasted either from using shortcuts : CTRL+C, CTRL+V or from using copy, paste option...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.