0

I'm having difficulty in using a WebView that is being used purely to display a preview of a website - and I want to ignore all/any interactions the user may try to make with it.

I've already tried Cocoa webView - Disable all interaction to no avail; you can still easily spam-click and it will recognise the presses. (at least there's no context menu)

This one seems overkill; Disable a WebKit WebView - there must be an easier way.

In iOS I know exactly how to solve this, but as a Cocoa newcomer I am stumped - does anyone have any suggestions or better ways to achieve this? Or dump a transparent NSView on top and gobble up interactions? (tried this as well by subclassing an NSView, also to no effect)

Whole project is in IB currently, if this makes any difference.

Community
  • 1
  • 1
Luke
  • 11,426
  • 43
  • 60
  • 69

1 Answers1

1

I think you want to implement a WebPolicy Delegate and have it deny navigation events.

Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • Wouldn't JavaScript click handlers still fire, though? – Peter Hosey Dec 16 '12 at 16:37
  • Ah okay great - now we're halfway there. I can verify what Peter has said now. Just such a shame there doesn't appear to be one tiny property to turn off all interaction. – Luke Dec 16 '12 at 16:56
  • There are several WebKit delegate protocols and I'm fairly certain you have full control over what is executed and what is not. It may be a "disable all JavaScript" or "allow all" scenario (not sure) but that may still work for you. Explore the other protocols and post any specific questions you may encounter. – Joshua Nozzi Dec 17 '12 at 15:13
  • Same problem. I was about to post a question. I can get links to die, but users can go on Google.com and search by pressing return. I was about to try blocking it with a transparent view, but I realized that scrolling would no longer work... AND I can't block Javascript because I still want it to work for stuff that the user doesn't touch. All I want to do is just make it say "no" to anything that would redirect the WebView somewhere. – sudo Oct 18 '13 at 06:50