问题
I can easily do this by using webkit.net's context menu:
private void browser1_NewWindowRequest(object sender, WebKit.NewWindowRequestEventArgs e)
{
((Form1)MdiParent).AddTab(e.Url.ToString());
}
However newWindowrequesteventargs e returns null for javascript events that prompt new tabs/windows, I can sort of fix it just by right clicking then clicking "open link" which does actually opens it in a new tab or window (as does clicking the regular "open in new window"). The following still does not work at all for buttons that prompt new windows only hyperlinks
private void browser1_NewWindowRequest(object sender, WebKit.NewWindowRequestEventArgs e)
{
if (e.Url.ToString() != null)
{
((Form1)MdiParent).AddTab(e.Url.ToString());
}
else
{
//I just need to stimulate the mouse right clicking and then left clicking for this to work but this still does not work for buttons, how can I get the link from the element the mouse is over?
}
}
This hypothetically would only work with links and not buttons, so I've been trying to look for the method done by the "Open Link" menu item in the control's native context menu I've look through the source of webkit.net but I cannot find anything, can someone help me out? I want to add webkitbrowser1.OpenLink(); to the control which would perform the same stuff clicking the "Open link" menu item would.
回答1:
I have solve the context menu, in the newwindowrequest event, you just put e.Url.Tostring() to get the current url, and you use your own add tab or window method to navigate to it. Still not sure on javascript
来源:https://stackoverflow.com/questions/17909425/webkit-net-opening-new-tabs-and-windows