Can any one please tell me how to cancel the event of new window opening in a wpf webbrowser in C#?I dont want to show the internet explorer window on top of my application when a link is clicked.
The webbrowser is defined as below:
<WebBrowser Canvas.Left="311.522" Canvas.Top="106.949" Height="500.805开发者_运维问答"
Width="945.998" ScrollViewer.VerticalScrollBarVisibility="Hidden"
ScrollViewer.CanContentScroll="False"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
HorizontalAlignment="Left" Name="wbNavigator" VerticalAlignment="Bottom" ClipToBounds="True" Navigated="wbNavigator_Navigated" />
Regards,
Ok, scroll to the bottom of this page. One of the users provides a solution that involves getting the IWebBrowser2 interface from the WPF WebBrowser control. This interface provides access to the NewWindow event, which can be used to cancel the opening of a new browser window. It seems like a valid solution to me.
Good luck and let me know if you need any more help with this.
Add this to your namespace works for me, I don't know why ... I found it here but I have used only this part of the code without MyWebBrowser.LoadCompleted and COM references stuffs
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("6d5140c1-7436-11ce-8034-00aa006009fa")]
internal interface IServiceProvider
{
[return: MarshalAs(UnmanagedType.IUnknown)]
object QueryService(ref Guid guidService, ref Guid riid);
}
If someone can explain why this code do the job, please...
精彩评论