ventanas permitir internet habilitar emergentes eliminar elementos desbloquear como bloqueador browser webbrowser-control vb.net-2010 popupwindow axwebbrowser

browser - permitir - Navegador web para manejar ventanas emergentes dentro de la aplicación



permitir ventanas emergentes safari iphone (1)

Estoy tratando de usar el control WebBrowser para lanzar un nuevo formulario para ventanas emergentes en lugar de abrirlo en IE. He intentado utilizar AxWebBrowser en su lugar para obtener las ventanas emergentes que funcionan con el evento NewWindow3 y simplemente haciendo e.ppDisp = AxWebBrowser.Application , pero hay muchas limitaciones que vienen con AxWebBrowser. Por lo tanto, en su lugar, estoy intentando extender el WebBrowser normal para incluir el evento NewWindow3 como AxWebBrowser, pero tengo problemas. Con e.ppDisp = AxWebBrowser.Application recibo errores: "InvalidVariant fue detectado" seguido de "La variante OLE especificada no es válida" si continúo.

Nota: Esta es la primera vez que extiendo una clase, así que podría estar buscando algo simple. Si intento simplemente navegar a la nueva URL en la nueva ventana, recibo errores de script de Java desde el sitio.

He actualizado el código base en los comentarios. Han eliminado la clase ExtendedWebBrowser para una versión más pequeña y más agradable. Aquí está el Nuevo Código:

Desde el formulario principal y un formulario BrowserPopup muy similar -

Protected Overrides Sub OnLoad(ByVal e As EventArgs) MyBase.OnLoad(e) nativeBrowser = DirectCast(ExtendedWebBrowser1.ActiveXInstance, SHDocVw.WebBrowser) AddHandler nativeBrowser.NewWindow3, AddressOf nativeBrowser_NewWindow3 AddHandler nativeBrowser.WindowClosing, AddressOf nativeBrowser_WindowClosing End Sub Private Sub nativeBrowser_NewWindow3(ByRef ppDisp As Object, ByRef Cancel As Boolean, ByVal dwflags As UInteger, ByVal bStrUrlContext As String, ByVal bstrUrl As String) Dim popup = New BrowserPopup() popup.Show(Me) popup.browserPop.DocumentText = bStrUrlContext ppDisp = popup.browserPop.ActiveXInstance End Sub Private Sub nativeBrowser_WindowClosing(ByVal IsChildWindow As Boolean, ByRef Cancel As Boolean) MsgBox("working?") ''<<<Doesn''t Trigger>>> End Sub Protected Overrides Sub OnFormClosing(ByVal e As FormClosingEventArgs) MyBase.OnFormClosing(e) End Sub

Además, si ayuda, aquí está la secuencia de comandos de la página que debería poder cerrar el formulario emergente pero parece que desactiva el WebBrowser.

<table isListBtn="false" cellpadding="0" enabled="true" class="buttonBorderBlue" cellspacing="0" border="0" onClick="if (typeof(workpaneMediator_toolbar)!=''undefined'') workpaneMediator_toolbar.onSelect(''CANCEL_ACTION'', this)" actionType="CLOSE_WINDOW_TYPE" id="workpaneMediator_toolbar_CANCEL_ACTIONWrapper" nowrap><tr><td class="buttonBlueTD">


Tiene razón al decir que WindowClosing no es despedido por Winforms WebBrowser Control, lo confirmo. Parece ser un error de larga data en el código de alojamiento .NET WebBrowser ActiveX, que nunca se ha abordado. Consulte esta publicación para obtener más detalles y una posible solución.

Otra posible solución alternativa puede ser el control WebBrowser ActiveX Control directamente a través de la clase AxHost , en cuyo caso WindowClosing se AxHost correctamente. Ejemplo:

DO#:

using Microsoft.Win32; using System; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WebBrowserApp { // MainForm public partial class MainForm : Form { WebBrowser webBrowser; public MainForm() { InitializeComponent(); InitBrowser(); if (this.webBrowser.Document == null && this.webBrowser.ActiveXInstance == null) throw new ApplicationException ("Unable to initialize WebBrowser ActiveX control."); var ax = (SHDocVw.WebBrowser)this.webBrowser.ActiveXInstance; ax.NewWindow2 += (ref object ppDisp, ref bool Cancel) => { var popup = new RawBrowserPopup(); popup.Visible = true; ppDisp = popup.WebBrowser.ActiveXInstance; }; this.Load += (s, e) => { this.webBrowser.DocumentText = "<a target=/"_blank/" href=/"javascript:''<button onclick=//'window.close()//'>Close</button>''/">Go</a>"; }; } // create a WebBrowser instance void InitBrowser() { this.webBrowser = new WebBrowser(); this.webBrowser.Dock = DockStyle.Fill; this.Controls.Add(this.webBrowser); this.webBrowser.Visible = true; } } // RawWebBrowser public class RawWebBrowser : AxHost { public RawWebBrowser() : base("8856f961-340a-11d0-a96b-00c04fd705a2") { } public event EventHandler Initialized; protected override void AttachInterfaces() { if (this.Initialized != null) this.Initialized(this, new EventArgs()); } public object ActiveXInstance { get { return base.GetOcx(); } } } // RawBrowserPopup public class RawBrowserPopup : Form { RawWebBrowser webBrowser; public RawWebBrowser WebBrowser { get { return this.webBrowser; } } public RawBrowserPopup() { this.webBrowser = new RawWebBrowser(); this.webBrowser.Initialized += (s, e) => { var ax = (SHDocVw.WebBrowser)this.webBrowser.ActiveXInstance; ax.NewWindow2 += (ref object ppDisp, ref bool Cancel) => { var popup = new RawBrowserPopup(); popup.Visible = true; ppDisp = popup.WebBrowser.ActiveXInstance; }; ax.WindowClosing += (bool IsChildWindow, ref bool Cancel) => { Cancel = true; this.Close(); }; }; this.webBrowser.Dock = DockStyle.Fill; this.Controls.Add(this.webBrowser); this.webBrowser.Visible = true; } } }

VB.NET:

Public Class Form1 Dim webBrowser As WebBrowser = New WebBrowser() Sub New() MyBase.New() Me.InitializeComponent() webBrowser.Dock = DockStyle.Fill Me.Controls.Add(webBrowser) webBrowser.Visible = True End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.webBrowser.DocumentText = "<a target=''_blank'' href=''javascript:""<button onclick=/""window.close()/"">Close</button>""''>Go</a>" Dim ActiveX As SHDocVw.WebBrowser = Me.webBrowser.ActiveXInstance AddHandler ActiveX.NewWindow2, AddressOf WebBrowser_ActiveX_NewWindow2 End Sub Private Sub WebBrowser_ActiveX_NewWindow2(ByRef ppDisp As Object, ByRef Cancel As Boolean) Dim popup As RawBrowserPopup = New RawBrowserPopup() popup.Visible = True ppDisp = popup.WebBrowser.ActiveXInstance End Sub End Class Public Class RawWebBrowser Inherits System.Windows.Forms.AxHost Sub New() MyBase.New("8856f961-340a-11d0-a96b-00c04fd705a2") End Sub Event Initialized(sender As Object, e As EventArgs) Protected Overrides Sub AttachInterfaces() RaiseEvent Initialized(Me, New EventArgs()) End Sub Public ReadOnly Property ActiveXInstance() As Object Get Return MyBase.GetOcx() End Get End Property End Class Public Class RawBrowserPopup Inherits System.Windows.Forms.Form Dim WithEvents rawBrowser As RawWebBrowser = New RawWebBrowser() Sub New() MyBase.New() rawBrowser.Dock = DockStyle.Fill Me.Controls.Add(rawBrowser) rawBrowser.Visible = True End Sub Public ReadOnly Property WebBrowser() As Object Get Return rawBrowser End Get End Property Private Sub rawBrowser_Initialized(sender As Object, e As EventArgs) Handles rawBrowser.Initialized Dim activeX As SHDocVw.WebBrowser = rawBrowser.ActiveXInstance AddHandler activeX.NewWindow2, AddressOf activeX_NewWindow2 AddHandler activeX.WindowClosing, AddressOf activeX_WindowClosing End Sub Private Sub activeX_NewWindow2(ByRef ppDisp As Object, ByRef Cancel As Boolean) Dim popup As RawBrowserPopup = New RawBrowserPopup() popup.Visible = True ppDisp = popup.WebBrowser.ActiveXInstance End Sub Private Sub activeX_WindowClosing(IsChildWindow As Boolean, ByRef Cancel As Boolean) Cancel = True Me.Close() End Sub End Class