• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2465
  • Last Modified:

VB.NET browser open new window paypal popup as new tab

I have learned how to intercept popups and open them as new tab.

Example VB.NET webbrowser handle new windows

This didnt work for paypal payment popup. It says:
Caller Input Exception: The following input(s) are not well formed:[transactionAmount]

However, the extended webbrowser control does it right.

I would like to understand why my code does not work for paypal popups. Any ideas?
0
wfskmoney
Asked:
wfskmoney
  • 4
  • 2
2 Solutions
 
ArkCommented:
There are 2 things your code doesn't handle while CodeProject does:
1. Error handling (see Handling Script Errors in CodeProject article). brws.ScriptErrorsSuppressed = True in your code won't load initial page properly if there are security alerts in scripts - it just interrupt script like yuo press "No" button.
2. (Most important) - you'r using 'simplified' Navigate2 method with Url only as argument. In your case paypal button use JSON postback, so URL is not enough (See #7 from "Enabling functionality for tabbed browsing or MDI browsing" in CodeProject article)
3. Check out VB version of  this article control at http://code.bn2vs.com/viewtopic.php?t=83
0
 
wfskmoneyAuthor Commented:
your suggestion 3. to try Check out VB version of  this article control at http://code.bn2vs.com/viewtopic.php?t=83 does not work, same error.

The codeproject extended browser written in C# works though.

Regarding 2: could you briefly explain or reference what is necessary in my VB.NET app to get it work? Must I add other data to the URL?
0
 
ArkCommented:
Hi
Though implementing DWebBrowserEvents2 and IWebBrowser2 interfaces is "Correct, Clean and M$ recommended way" (heh), much easy is using existing SHDocVW ActiveX object which already implements thosuse interface.
According #2 - except URL, paypal button post form data to server. There are 2 ways to open popup in webbrowser using shdocvw:
1. Cast Neet webbrowser to shdocVW.Webbrowser_V1, intercept NewWindow event and navigate with another shdocVW.Webbrowser_V1 with url,headers,postdata etc. Unfortunatelly, setting Processed to true doesn't prevent server-build popups from showing - youl get 2 paypal instancies - one in popup window, another in a tab (commented part in example attached - just to see headers and postdata)
2.  Cast Neet webbrowser to shdocVW.Webbrowser, Intercept NewWindow2 event and redirectt output (ppDisp object) to AxPop.Application

Actually, all code using ShdocVw contains few strings:
1. Add reference to ShdocVw (project->references->Add->Com Tab->Microsoft Internet Controls)
2. Add 2 webbrowsers - wbMain and wbPop (place them into tab control if you like)
   Private WithEvents AxMain As SHDocVw.WebBrowser
    Private AxPop As SHDocVw.WebBrowser 'Add with events if you like

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       'Initialize instancies to prevent Null reference exception
        wbPop.Navigate("about:blank")
        wbMain.Navigate("about:blank")
       'Cast Net webbrowsers to ActiveX
        AxMain = CType(wbMain.ActiveXInstance, SHDocVw.WebBrowser)
        AxPop = CType(wbPop.ActiveXInstance, SHDocVw.WebBrowser)
        AxMain.Navigate("https://secure.savethechildren.org")
    End Sub

    Private Sub AxMain_NewWindow2(ByRef ppDisp As Object, ByRef Cancel As Boolean) Handles AxMain.NewWindow2
        ppDisp = AxPop.Application 'Redirect output
    End Sub

Open in new window


Thats all :)
frmPop.zip
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ArkCommented:
PS. A bit more correct code - if wbPop is busy (ie if you first redirect another pop) seems server loads paypal forever. Workaround:
    Private Sub AxMain_NewWindow2(ByRef ppDisp As Object, ByRef Cancel As Boolean) Handles AxMain.NewWindow2
        wbPop.Navigate("about:blank")
        While wbPop.ReadyState <> WebBrowserReadyState.Complete
            My.Application.DoEvents()
            Threading.Thread.Sleep(100)
        End While
        ppDisp = CType(wbPop.ActiveXInstance, SHDocVw.WebBrowser).Application
    End Sub

Open in new window

0
 
wfskmoneyAuthor Commented:
Fantastic, works perfect!
0
 
ArkCommented:
Thanks for points, glad I could help
You can use 'Normal' popup behavior as well.
Method 1: Show popup in your form:
 Private Sub AxMain_NewWindow2(ByRef ppDisp As Object, ByRef Cancel As Boolean) Handles AxMain.NewWindow2
       Using f As New frmPopUp 
            f.Show()
            f.WebBrowser1.Navigate("about:blank")
            While f.WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
                My.Application.DoEvents()
                Threading.Thread.Sleep(100)
            End While
            ppDisp = CType(f.WebBrowser1.ActiveXInstance, SHDocVw.WebBrowser).Application
        End Using
    End Sub 

Open in new window

Method 2: Using native IE window via automation
   Private WithEvents shellWnds As SHDocVw.ShellWindows
   Private dctWindows As New Dictionary(Of Integer, SHDocVw.InternetExplorer)
'.... In Form_Load event
   shellWnds = New SHDocVw.ShellWindows
'........

    Private Sub shellWnds_WindowRegistered(ByVal lCookie As Integer) Handles shellWnds.WindowRegistered
        'Debug.Print("Registered:")
        UpdateCollection()
        For Each ie As SHDocVw.InternetExplorer In dctWindows.Values
            'Debug.Print(ie.LocationURL)
            If ie.LocationURL.ToLower.Contains("paypal") Then
                If ie.LocationURL.ToLower.Contains("savethechildren") Then
                    MsgBox("Found paypal for savethechildren:" & vbCrLf & ie.LocationURL)
'Dim doc as mshtml.HTMLDocument = ie.Document
'Access to all elements via DOM interface
'For example:doc.getElementById("cc_number").value="123456"
'doc.Forms("billing_form").submit
                End If
            End If
        Next
    End Sub

    Private Sub shellWnds_WindowRevoked(ByVal lCookie As Integer) Handles shellWnds.WindowRevoked
        Debug.Print("Revoked:")
        UpdateCollection()
        For Each ie As SHDocVw.InternetExplorer In dctWindows.Values
            Debug.Print(ie.LocationURL)
        Next
    End Sub

    Private Sub UpdateCollection()
        dctWindows.Clear()
        Dim counter As Integer
        For Each w As Object In shellWnds
            Dim ie As SHDocVw.InternetExplorer = TryCast(w, SHDocVw.InternetExplorer)
            If Not ie Is Nothing Then
                dctWindows.Add(counter, ie)
                counter += 1
            End If
        Next
    End Sub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now