NewWindowDispatch
Interface AntViewNewWindowRequestedEventArgs
Type: Method
Parameters: IDispatch* Browser
Returns: nothing
The new browser control to use for this new window.
This method is needed if you want to use this from within VB6.
See also NewWindow.
Sometimes you need to connect the new window to a new browser. For example if you need to support the http post interface then you can't just pass the Url to the new window.
Below is some visual basic example code on how you can do this.
We have a html page with the following content:
<!DOCTYPE HTML>
<html>
<head>
<script src="NewWindow.js"></script>
</head>
<body>
</body>
</html>
and the javascript file looks like this:
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "<https://www.yahoo.com>");
function popitup(url) {
newwindow = window.open(url, 'name', 'width=800,height=600');
if (window.focus) {
newwindow.focus()
}
newwindow.document.body.appendChild(form);
newwindow.document.forms[0].submit();
return false;
}
popitup();
So what we have here is a non user initiated popup that opens a page in another domain while trying to post a form.
In Visual Basic we have two forms, form1 and form2, both have an AntView component on it called "browser".
Here's the content of form1.
Option Explicit
Public WithEvents DeferWindow As AntViewAx2.AntViewDeferral
Public WithEvents NewWindowArgs As AntViewAx2.AntViewNewWindowRequestedEventArgs
Private Sub Form_Load()
Set DeferWindow = New AntViewAx2.AntViewDeferral
Set NewWindowArgs = New AntViewAx2.AntViewNewWindowRequestedEventArgs
browser.UnlockControl "ExampleCompany", "WI5PO2-2KSU3Q-HWFXFU-IUMU2V-QF8P2F"
browser.CreateWebView
browser.EventsUseHexadecimal = True
browser.Navigate "https://antwise.com/demo/NewWindow.html"
End Sub
Private Sub browser_OnNewWindowRequested(ByVal Args As AntViewAx2.IAntViewNewWindowRequestedEventArgs)
Dim URI As String
URI = Args.URI
Debug.Print "New Window: " & URI
Load Form2
Form2.Show
Args.Handled = True
Debug.Print "user initiated = " & Args.UserInitiated
Set NewWindowArgs = Args
Set DeferWindow = Args.Deferral
End Sub
We create a NewWindowArgs object as it takes time for the new browser object in form2 to create itself. We also use the AntViewDeferral object to indicate that to the OnNewWindowRequested event that it should defer the event.
form2 looks like this:
Option Explicit
Private Sub Form_Load()
browserPopup.UnlockControl "ExampleCompany", "WI5PO2-2KSU3Q-HWFXFU-IUMU2V-QF8P2F"
browserPopup.CreateWebView
browserPopup.EventsUseHexadecimal = True
End Sub
Private Sub browserPopup_OnCreateWebviewCompleted(ByVal HResult As Long)
Debug.Print "popup triggered"
Form1.NewWindowArgs.NewWindowDispatch (browserPopup.IDispatchPointer)
Form1.DeferWindow.Complete
End Sub
Introduced in AntView release 1.1.314
AntView - The MS Edge WebView2 ActiveX control Date last changed: 09/30/2024