views:

58

answers:

2

I'm wondering whether it's possible to use JavaScript to intercept or prevent the user from using the browser's "Find" feature to find text on the page. (Trust me, I have a good reason!) I'm guessing the answer is "no," beyond the obvious intercepting Cmd/Ctrl+F.

A second-best solution would be to intercept the text highlighting that the browser performs during a Find. Is there any way to do this, in any browser?

+4  A: 

Not without the help of a browser-specific extension I think, if at all. This is a process that is entirely outside the JavaScript context.

Pekka
And thanks god!
doublep
You're sure there aren't any events fired when a browser Find highlights some text on the page? In any browser? Since you can copy the selected text to the clipboard, I would think there would be a change in the selected text property somewhere, which you could distinguish from a mouse or keyboard event that would normally select text.
Trevor Burnham
@Trevor in Firefox, the "find" selection is different from the standard selection. It can not be copy+pasted, nor deleted. I'm 99% sure this is not a normal selection and the selected text property will not change. (I can't test it in depth right now but I'd be surprised if I turned out to be wrong.) In IE 8, though, it looks like the normal selection is manipulated. You may be successful there.
Pekka
@Trevor Pretty definite for FF, I tested http://api.jquery.com/select/ the example doesn't work in IE either but that may be down to a text input specific behaviour.
Pekka
+1  A: 

If you really, absolutely have to do that - then there's a (really bad) solution: Render the page as an image.

Chris Lercher
catpcha rules ;)
Jhonny D. Cano -Leftware-
No, I need to preserve other behaviors; for instance, I want the user to be able to select text with the mouse, and enter text. I just want to avoid them selecting it with Find.
Trevor Burnham