/    Sign up×
Community /Pin to ProfileBookmark

Preventing Paste in Mozilla

Hi,

I need to be able to prevent users from Pasting some text into a text field when using a Mozilla Firefox. This is working for the IE. Onpaste doesn’t work for mozilla so could someone please give me an idea of how to do this? I just need a basic check to prevent the majority of users from pasting.

Thanks a lot ?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@chug187Feb 01.2007 — Well, this is what you're looking for:

[CODE]<textarea oncontextmenu="return false" onkeydown="return !((event.keyCode == 86) && (event.ctrlKey));"></textarea>[/CODE]

But note that if a user doesn't have JavaScript enabled they'll be able to paste all they want, so you'll never be able to fully disallow pasting.

Cheers,

Matt
Copy linkTweet thisAlerts:
@Wisest_GuyFeb 01.2007 — You can't control their computers if they don't want you to.
Copy linkTweet thisAlerts:
@ghostyauthorFeb 01.2007 — Oops, i forgot to mention that i am using struts as well.

So instead of <textarea> i have <html:text> and oncontextmenu isn't supported.

To handle this problem in IE, i have an onBodyLoad() method and am getting my text field; text and doing text.onpaste = onMyPaste; onMyPaste just returns a message saying not allowed to paste and false;

how would i handle this for mozilla. calling text.oncontextmenu = myOnContextmenu; doesn't even go into the method unless i call

text.oncontextmenu = onMyContextmenu(); which then only gets called when the page is loading, but it doesn't get called again.

And i'm aware these check won't work for everyone, but trying to catch the majority ?

Thanks

Ana
Copy linkTweet thisAlerts:
@ghostyauthorFeb 01.2007 — Never mind! Got it working, yey!

Thanks for all the help?
×

Success!

Help @ghosty spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...