I am having the exact same issue with a WinForms WebBrowser control and the onbeforeunload javascript event handling as this post (How to intercept the onbeforeunload event in a WebBrowser control?). I tried the same solution as presented to cast the onbeforeunload event to IDispatch and call the Invoke method. I get this error when doing so:
hr = -2147352319
I'm developing in .NET 3.5 on WinXP using IE 6.0.
I did not put the C# code here because it is exactly the same as the linked article above.
The JavaScript code is :
function onBeforeUnload()
{
if (window.cObject.isTransferred)
{
event.returnValue = "\nYou are requesting to exit.\n";
}
else
{
event.returnValue = "\nYou are DELETING this object!!!\n";
}
}