Reputation: 57373
I'm using a WPF WebBrowser control to preview HTML typed by the user.
example...
WPF TextBox and WebBrowser controls http://img411.imageshack.us/img411/2296/appbz9.jpg
But, how do I made the WebBrowser control read-only? I don't want the user to be clicking links in there and navigating away from the preview page.
I want my users to create links. I just want to make sure the "preview" pane is a preview of the correct page.
Upvotes: 3
Views: 6156
Reputation: 1
Have anyone tried with WebBrowserControl.AllowNavigation = False I think this will do. You can enable and disable the property as you need during runtime. I use a Timer to disable the property with a custom latency, so that the document has time to load.
Good luck, Dan
Upvotes: -1
Reputation: 57373
Capture the Navigating event of the WebBrowser control and set the Cancel property of its NavigatingCancelEventArgs to True.
Visual Basic code...
Private Sub WebBrowser1_Navigating(...) Handles WebBrowser1.Navigating If WebBrowser1Locked Then e.Cancel = True End If End Sub
This requires a global locking boolean variable.
Partial Public Class Window1 Dim WebBrowser1Locked As Boolean = True ... End Class
And locking and unlocking to be wrapped around the desired navigation.
WebBrowser1Locked = False WebBrowser1.NavigateToString("...") WebBrowser1Locked = True
Upvotes: 8
Reputation: 5107
Maybe you can catch the control's click event and throw it away before it tries to navigate to the link? I'm not sure if it's possible but I'd try that.
Upvotes: 2
Reputation: 25941
Can't you just place a transparent window over the entire control and capture all the mouse and keyboard events there?
Upvotes: 6
Reputation: 17528
You will have to sanitize the input.
Do not allow anchor or script tags or on attributes. (I don't know if you can disable javascript on the control, but that would be a good idea to.
Upvotes: 1