views:

33

answers:

2

Hi there

Does someone have know how to trap clicks on Links in the WPF WebBrowser Control?

I need to get the links target, when the link is clicked, before the Page is navigating.

Any inputs highly appreciated!

My solution in Code As proposed for simple Links this would be achieved with the following code:

private void webBrowser1_Navigating(object sender, NavigatingCancelEventArgs e)
{
    //prefix must be lowercase (ssrs conforms to web-standards and makes things lowercase)
            string myPrefix = "http://myPrefix";

            //check if target starts with the prefix
            if (e.Uri.AbsoluteUri.StartsWith(myPrefix))
            {
                //cancel Navigation
                e.Cancel = true;
            }
}

Thank you for hepling me out on this.

+1  A: 

You can attache an event handler to the Navigating event. Extract the link , execute your logic before the page is navigated.

Cheers.

DrakeVN
But sometimes link clicking does not cause navigation, but executes a javascript handler.
STO
Thank you two@DrakeVN, I did try to get all the links in the loaded Page in the Navigated event, and there adding events for every single Link. But this gets a bit hairy as one needs to work with many com_objects. And a lot seemed to change, compared to the WebBrowser Control in Windows Forms. I'll try your simpler approach.@STO: links with javascript handlers shouldn't be a problem in my case, as I use the trapped links in Reporting Services to open the according elements.
SwissCoder
+1  A: 

I'm not sure about that, but may be MessageHook event helps you

http://msdn.microsoft.com/en-us/library/system.windows.interop.hwndhost.messagehook.aspx

STO
Tahnks, I guess there should be a simpler way, and the following doesnt allow me to use it:Security Note This type or member is not available in the Internet security zone.
SwissCoder