Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Copy

Status
Not open for further replies.

alsaffar

Programmer
Oct 25, 2001
165
KW
Hi there,

I found very cool trick to disable copy by executing the following line in OnLoad argument:

block = setInterval("window.clipboardData.setData('text','')",20);

What it does, is preventing you while the page is open from copying anything "even from outside your page"

and you should execute the following line in OnUnLoad argument to enable the copying after your website is closed:

clearInterval(block);

I have 2 questions:

1) If you just opened the page, you can do 1 quick copy "and its not disabled yet", but if tried again, its disabled. Why is that! and what does it mean the figure "20" in the setinterval statment?

2) In my home pc which is (WIN XP, IE 6.5) its working prefect, but in my work pc which is (WIN 2000, IE 5.0) the minute I opened my webpage "it bomb" giving an error "iexplorer.exe has generated errors and will be closed by windows"! Why is that! Up to my knowledge that javascript might work on some versions but not bomb on old versions!

Please advice on the above 2 questions ;)
 
The setInterval only begins once the page has loaded. This is not instantaneous and can take several seconds (or more) before the setInterval starts... and then you have to wait until the setInterval has fired (after the interval you set - 20 milliseconds above).The 20 in the setInterval is the frequency/interval that the setInterval will run at (in milliseconds).

The command is being run every 20 milliseconds... and that's probably a bit too fast. I would suggest changing it to 500 (half a second) and see if that improves performance on your work pc.

The following URL shows some code to make this work on Netscape/Mozilla browsers as well:
Chers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Of course, it's pretty much useless code anyway. There are any number of ways around not being able to copy to the clipboard:
[ol]
[li]Turn off javascript and you can copy all you want.[/li]
[li]Use a program to capture the screen image.[/li]
[li]Print the page.[/li]
[li]View source and then copy to the clipboard from there.[/li]
[/ol]
All you're doing is making it a tiny bit more difficult, tying up cpu cycles on the user's machine, and wasting your time trying to make it work.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top