[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2012-08-15
6
Medium Priority
?
2,343 Views
Last Modified: 2016-03-24
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
Comment
Question by:wfskmoney
  • 4
  • 2
6 Comments
 
LVL 28

Expert Comment

by:Ark
ID: 38298530
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
 

Author Comment

by:wfskmoney
ID: 38298658
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
 
LVL 28

Accepted Solution

by:
Ark earned 2000 total points
ID: 38299595
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Assisted Solution

by:Ark
Ark earned 2000 total points
ID: 38299656
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
 

Author Closing Comment

by:wfskmoney
ID: 38302834
Fantastic, works perfect!
0
 
LVL 28

Expert Comment

by:Ark
ID: 38303057
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question