久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

Implementing a PopUp blocker into a WebBrowse...

 順溜的書架 2013-03-30

The main idea of Blocking unwanted pop-ups in that document:

Pop-ups are most of the time not very welcome, or could be inappropriate. To block these things, some additional information is needed. NewWindow3 gives this information when the user uses Windows XP SP2, or Windows 2003 SP1 or better. If this event is not fired, NewWindow2 takes its place. When NewWindow3 is fired, you can check:

  • If the user initiated the action that leads to the new window
  • If the user holds the override key (the Ctrl Key)
  • If it is a pop-up displayed because of a window that is closing
  • The URL that is going to be opened
  • And more...

Using NewWindow3 clearly is very interesting for this purpose. To use this event, DWebBrowserEvents2 needs to be implemented.

Solution:

  1. Implement DWebBrowserEvents2
  2. Create a new event and a new event arguments class
  3. Launch this event with the appropriate information
  4. After the event is fired, see if the navigation needs to be canceled

 

Hi Travy,

Here are three more intuitionistic approaches:

 

1. Use the AxWebBrowser ActiveX control, and handle AxWebBrowser_NewWindow2 event and AxWebBrowser_NewWindow3 event.

    

    Right-click the ToolBox -> select Choose Items -> Select the COM tab -> Select "Microsoft Web Browser"

   The Microsoft Web Browser control will be added in the toolbox, then drag it onto your form.

   

Code Snippet

Public Class Form1

 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        AxWebBrowser1.Navigate("http://www.ccb.com")

    End Sub

 

    Private Sub AxWebBrowser1_NewWindow2(ByVal sender As System.Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NewWindow2Event) Handles AxWebBrowser1.NewWindow2

        e.cancel = True ' blocking pop up new window

    End Sub

 

    Private Sub AxWebBrowser1_NewWindow3(ByVal sender As System.Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NewWindow3Event) Handles AxWebBrowser1.NewWindow3

        e.cancel = True ' blocking pop up new window

    End Sub

 End Class

 

 

2. Use the AxWebBrowser ActiveX control, and handle AxWebBrowser_NavigateComplete2 event.

Code Snippet

Public Class Form1

 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        AxWebBrowser1.Navigate("http://www.ccb.com")

    End Sub

 

    Private Sub AxWebBrowser1_NavigateComplete2(ByVal sender As System.Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) Handles AxWebBrowser1.NavigateComplete2

        ' Get a reference to the app that has opened in AxWebBrowser1 object

        Dim oDocument As Object = e.pDisp.Document

        oDocument.parentWindow.execScript("window.alert=null; ")

        oDocument.parentWindow.execScript("window.confirm=null; ")

        oDocument.parentWindow.execScript("window.showModalDialog=null; ")

        oDocument.parentWindow.execScript("window.open=null; ")

    End Sub

End Class

 

3. Using thread to monitor Popup windows and send message to close popup window.

Code Snippet

Imports System.Runtime.InteropServices

Imports System.Threading

 

Public Class Form1

 

    Private Const WM_SYSCOMMAND As Long = &H112

    Private Const SC_CLOSE As Long = &HF060 ' Close window

 

    ' P/Invoke FindWindow API

    <DllImport("User32.dll")> _

    Public Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As Int32

    End Function

 

    ' P/Invoke SendMessage API

    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _

    Public Shared Function SendMessage(ByVal hWnd As Integer, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer

    End Function

 

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

         WebBrowser1.Navigate("http://www.ccb.com")

        ' Run thread

            Dim s As ThreadStart = New ThreadStart(AddressOf ClosePopup)

            Dim myThread As Thread = New Thread(s)

            myThread.Start()

    End Sub

  

    ' Send Close message to the Popup window

    Public Sub ClosePopup()

       Dim handle As IntPtr

       While True

           handle = FindWindow(Nothing, "Popup Window Title")

           If handle <> IntPtr.Zero Then

               SendMessage(wordHandle, WM_SYSCOMMAND, SC_CLOSE, 0)

           End If

       End While

    End Sub

 

End Class

Trackback: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2794291&SiteID=1

How to Maximize/Minimize/Restore/Close a window through SendMessage API?

 

 

Check this thread for reference:

http://www./group/microsoft.public.dotnet.languages.csharp/topic10556.aspx

Does WebBrowser control in .net 2.0 support blocking pop-up windows?

 

 

I hope that can help you.

 

 

Good luck!

Martin

    本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點(diǎn),。請注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào),。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多