0

I am developing a logging system that detects when the hyperlinks stored in an html webpage (in turn, stored into a C# WebBrowser object) are clicked.

I am using the NewWindow event, but in order for the event to be logged, the window must be closed (ie: I can't log more than one click for the same hyperlink). I would like to record every single click, regardless of the fact that the window the hyperlinks refer to is open or not.

Any ideas about how to do it?

Cheers

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
gugu917
  • 9
  • 1
  • 5
  • 1
    There's no native way that I'm aware of. I'd insert Javascript into the page to achieve this. – Equalsk Dec 08 '17 at 15:29

1 Answers1

0

Do you absolutely need to track the click itself, or can you track the result of the click?

You can use the Navigating and Navigated events to detect when the user navigates to another page.

That gap between that and your question is that these events a) don't capture when a link is clicked that doesn't result in navigation, and b) do capture navigation that wasn't caused by clicking a link.

If you're using the control to display your own website, which you can modify, then you can raise events from within your page using Javascript that can be monitored by the application hosting the control. Here's an answer providing more detail on that.

In that scenario you're adding JavaScript event handlers to the click event of your links. Those event handlers in turn call window.external.SomeMethod(args), and the browser control invokes your C# method and passes the arguments to it.

Scott Hannen
  • 27,588
  • 3
  • 45
  • 62