Page 2 of 4 FirstFirst 1234 LastLast
Results 41 to 80 of 135

Thread: Webbrowser Control Tip and Examples

  1. #41
    Addicted Member
    Join Date
    Jul 2007
    Location
    Slovenia
    Posts
    131

    Question Re: Webbrowser Control Tip and Examples

    When I click 'Open', it doesn't want to. It doesn't show any errors or anything, nothing happens.

    VB Code:
    1. Private Sub menuFileOpen_Click()
    2. wWeb.ExecWB OLECMDID_OPEN, OLECMDEXECOPT_PROMPTUSER
    3. End Sub

    Can anyone help me?

  2. #42
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: Webbrowser Control Tip and Examples

    Hello,
    I'm using this code from a previous example in thread.

    Private Sub Command1_Click()
    WebBrowser1.Document.All("q").focus
    End Sub

    Private Sub Form_Load()
    WebBrowser1.Navigate "http://www.google.com/"
    End Sub

    It all works great. But due to the lack of documentatiion I can seem to find a way of entering something in the text box and then reloading the page. Any help would be greatly appreciated. Or even a link to some documentation would work too.

    Thanks

  3. #43
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: Webbrowser Control Tip and Examples

    Figured it out. Just in case anyone is interested, this works.

    Code:
    WebBrowser1.Document.All("q").focus
    WebBrowser1.Document.All("q").Value = "blah blah"
    WebBrowser1.Document.All("btng").focus
    WebBrowser1.Document.activeElement.Click
    Cheers...

  4. #44
    New Member
    Join Date
    Oct 2007
    Posts
    14

    Re: Webbrowser Control Tip and Examples

    i keep getting an Error 91 message. Anyone know why?

  5. #45
    New Member
    Join Date
    Oct 2007
    Posts
    14

    Re: Webbrowser Control Tip and Examples

    The codes here dont seem to be working for me. I can get the page loaded using:

    Code:
    Private Sub Command0_Click()
    
    Dim webBrowser1 As WebBrowser
    
        Set webBrowser1 = New WebBrowser
        Set webBrowser1 = CreateObject("InternetExplorer.Application")
    With webBrowser1
        .Navigate "http://www.ncl.com/edocs"
        .Visible = True
    
    .Document.Forms(0).all("txtResID").focus
    .Document.Forms(0).all("txtResID").Value = "blah blah"
    End With
    End Sub
    but nothing fills in and i get the error 91 message the .Document.Forms(0) line

  6. #46
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: Webbrowser Control Tip and Examples

    Code:
    .Document.all("txtResID").focus
    .Document.all("txtResID").Value = "blah blah"
    Try making the following changes....

  7. #47
    New Member
    Join Date
    Oct 2007
    Posts
    14

    Re: Webbrowser Control Tip and Examples

    now i get an error that says "Runtime error -2147467259 (80004005) Autmation Error Unspecified Error)

  8. #48
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: Webbrowser Control Tip and Examples

    Code:
    Private Sub Form_Load()
    WebBrowser1.Navigate "http://www.ncl.com/edocs"
    End Sub
    
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    
    With WebBrowser1
        .Document.Forms(0).All("txtResID").focus
        .Document.Forms(0).All("txtResID").Value = "blah blah"
    End With
    
    End Sub
    This won't load IE but use the webbrowser control in the form.

  9. #49
    New Member
    Join Date
    Oct 2007
    Posts
    14

    Re: Webbrowser Control Tip and Examples

    That code tells me WebBrowser1 is not defined. Don't i need to dim it somewhere?

    bwt - im using VB through MS Access.

  10. #50
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: Webbrowser Control Tip and Examples

    Ahhhh..Ok. Let me think about this because my code works fine in VB. I tested it.

    Do you have access to the "microsoft internet control", ieframe.dll? If so, just add it to your project and that will be the end of it.

  11. #51
    New Member
    Join Date
    Oct 2007
    Posts
    14

    Re: Webbrowser Control Tip and Examples

    yes i have that added.

  12. #52
    New Member
    Join Date
    Oct 2007
    Posts
    14

    Re: Webbrowser Control Tip and Examples

    im using the microsoft internet control library, but its called "shdocvw.dll". What is "ieframe.dll"?

  13. #53
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: Webbrowser Control Tip and Examples

    Let me try a few things in Access..

  14. #54
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: Webbrowser Control Tip and Examples

    Sorry about the ieframe thing. You're right, it's shdocvw.dll.

  15. #55
    New Member
    Join Date
    Oct 2007
    Posts
    14

    Re: Webbrowser Control Tip and Examples

    thank you for helping me out with this. I've been going nuts for the past week trying to get this to work!

    In Access i have a button that launchs this code OnClick (if that helps any).

  16. #56
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: Webbrowser Control Tip and Examples

    Well..I'm new to Access 2007 (sometimes hard to figure where things are in a new version) and I don't see the internet control component and I've tried a few things but I can't seem to add it. So I have no way of helping you in Access.

    My guess as to what your problem is that you're trying to access the text box before the page is fully loaded. Add the navigate command to the form_load part (get rid of it from the button click event). Once the page is fully loaded, click your button. Hope this helps.

  17. #57
    New Member
    Join Date
    Oct 2007
    Posts
    14

    Re: Webbrowser Control Tip and Examples

    in the VB editor: Tools > References > Microsoft Internet Controls.

    i tried adding:

    Code:
    Do Until webBrowser1.Busy = False
    Do Events
    Loop
    to make sure the page was fully loaded, but that doesnt work either.

  18. #58
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: Webbrowser Control Tip and Examples

    I got that far but I can't actually add the component to the form. Were you able to actually add the component to your form? Are you using Access 2007?

  19. #59
    New Member
    Join Date
    Oct 2007
    Posts
    14

    Re: Webbrowser Control Tip and Examples

    im using Access 2003. To add it to the form, you just make sure the box next to it is checked, yes?

  20. #60
    New Member
    Join Date
    Oct 2007
    Posts
    14

    Re: Webbrowser Control Tip and Examples

    i definitely think my problem is that its not waiting for the browser to stop loading.

    if i add an If webBrowser1.Busy = False statement around my .document lines, i get no error, but at the same time it doesnt fill in the fields.

  21. #61
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: Webbrowser Control Tip and Examples

    If I were using 2003 I wouldn't have any problems. Welcome to the World of 2007. If I figure it out I will post back..

  22. #62
    New Member
    Join Date
    Oct 2007
    Posts
    14

    Re: Webbrowser Control Tip and Examples

    ok thats definitely my problem. I found a sub ruitine that Pauses for given amount of time, so i made it pause for 10 seconds, and it works!

    Except, thats not a very reliable way of doing it in case the page takes a longer time to load for some reason.

    how can i just have it check that the page is done and completely loaded?

  23. #63
    New Member
    Join Date
    Oct 2007
    Posts
    11

    Re: Webbrowser Control Tip and Examples

    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)

    Code:
    With WebBrowser1
        .Document.Forms(0).All("txtResID").focus
        .Document.Forms(0).All("txtResID").Value = "blah blah"
    End With
    
    End Sub
    FYI. My toolbox in Access is greyed out and I can't get to it..Seems like there's lots of others in my situation out there...

  24. #64
    New Member
    Join Date
    Oct 2007
    Posts
    14

    Re: Webbrowser Control Tip and Examples

    ok it definitely works now.

    to make it wait i used:

    Code:
    Do Until webbrowser1.ReadyState = READYSTATE_COMPLETE
    DoEvents
    Loop
    but now i need to figure how to click the "submit" button on the page. How do i go about that?

  25. #65
    New Member
    Join Date
    Oct 2007
    Posts
    14

    Re: Webbrowser Control Tip and Examples

    I'm trying to use the "Check if word/string is found on page" code on the first page of this thread, but keep getting an Error 91 message on this line:

    Code:
    For i = 1 To WebBrowser1.Document.All.length
    First i got an object not defined error because "webBrowser1" wasnt Dim'd, so i dim'd it as "Dim webBrowser1 as webbrowser" but now i need to SET it to something - i just dont know what i SET it to. Anyone know?

  26. #66
    New Member
    Join Date
    Nov 2007
    Posts
    3

    Re: Webbrowser Control Tip and Examples

    I realize this may sound odd...but can the Webbrowser Control be embedded in a HTML page? If so how would I do it?

    I'm building a Folder Home Page to replace my Outlook Today and would like to be able to use it as a file browser right on the page.

  27. #67
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Webbrowser Control Tip and Examples

    Quote Originally Posted by dch31969
    I realize this may sound odd...but can the Webbrowser Control be embedded in a HTML page? If so how would I do it?

    I'm building a Folder Home Page to replace my Outlook Today and would like to be able to use it as a file browser right on the page.
    Use an iframe element.

  28. #68
    New Member
    Join Date
    Nov 2007
    Posts
    3

    Re: Webbrowser Control Tip and Examples

    Quote Originally Posted by penagate
    Use an iframe element.
    Ok...I know how to put an iframe into a HTML page, but given that I had no idea until yesterday that the WebBrowser control existed, could you please provide me with the syntax? I should be able to figure things out from there.

  29. #69
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Webbrowser Control Tip and Examples

    sorry, I didn't mean embed the WebBrowser using an iframe, but just point the iframe to the directory you want to browse.

  30. #70
    New Member
    Join Date
    Nov 2007
    Posts
    3

    Re: Webbrowser Control Tip and Examples

    Quote Originally Posted by penagate
    sorry, I didn't mean embed the WebBrowser using an iframe, but just point the iframe to the directory you want to browse.
    So its not possible to present an Explorer like interface complete with folders, drives, files? I'm essentially looking give my users everything that they have when they explore their PCs.

  31. #71
    New Member
    Join Date
    Feb 2008
    Posts
    2

    Re: Webbrowser Control Tip and Examples

    That auto submit thing is good With WebBrowser but how do u find the exact Thing to be written like. If i do it on. http://login.yahoo.com Then if i view html code for this page i see Document.Write. So I write it like this

    WebBrowser1.Document.Write.passwd.value = strpw

    passwd is PASSWORD so it doesnt work

  32. #72
    New Member
    Join Date
    Feb 2008
    Posts
    2

    Re: Webbrowser Control Tip and Examples

    Nvm It Works Thanks For The Help By msgjp7

  33. #73
    Member vali20's Avatar
    Join Date
    Feb 2008
    Posts
    58

    Re: Webbrowser Control Tip and Examples

    Hi, if you know, I need some codes! For the find box (when I start the find box and start searching a word, I want webbrowser to highlight it). I need codes for the right click menu, such as 'Save Picture As...'; 'E-mail Picture'; 'Print Picture'; 'Set as Background'; 'Set as Desktop Item'; 'Copy Shortcut'; 'Add to favorites'; 'Open link'; 'Open link in new window'; 'Save Target as...'; 'Print Target'. I want to know, if I have open form1, how to open a NEW form1 with a commandbutton? Please help with these problems!

  34. #74
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Webbrowser Control Tip and Examples

    Is there any way to block pop ups.???

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  35. #75
    Lively Member
    Join Date
    Aug 2008
    Location
    Between the keyboard and the chair.
    Posts
    122

    Re: Webbrowser Control Tip and Examples

    Here is my current code:
    Code:
    Option Explicit
    
    Dim doc As HTMLDocument
    
    Private Sub Command1_Click()
        WebBrowser1.Navigate "http://www.google.com"
    End Sub
    
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        Dim i As Long, EHTML
        For i = 1 To WebBrowser1.Document.All.length
            Set EHTML = _
            WebBrowser1.Document.All.Item(i)
    
            If Not (EHTML Is Nothing) Then
                If InStr(1, EHTML.innerHTML, "Google", vbTextCompare) > 0 Then
                    Replace EHTML.innerHTML, "Google", "Boogle"
                End If
            End If
        Next i
        doc = WebBrowser1.Document
    End Sub
    Basically, supposed to replace every Google string with Boogle. Works, as I tested with MsgBox, but the thing is EHTML doesnt writeback to the page, so EHTML is changed, while whats being displayed isn't. Any way to writeback the changes without reloading the page?

  36. #76
    Lively Member
    Join Date
    Jun 2008
    Posts
    91

    Question Re: Webbrowser Control Tip and Examples

    Custom Right Click Menu
    This is an example show how to make your own custom right click menu. in order for this to work you must add the "Must Add Microsoft HTML Object Library" to your refrance.Also make your own custom menu using the menu editor I named my "mnu"
    Please Note it will effect all the context menus in the webbrowser.

    VB Code:
    1. 'Must Add Microsoft HTML Object Library
    2. Option Explicit
    3.     Public WithEvents HTML As HTMLDocument
    4.  
    5. Private Function HTML_oncontextmenu() As Boolean
    6.    HTML_oncontextmenu = False
    7.    PopupMenu mnu '<---Check the mnu to your own menu name
    8. End Function
    9.  
    10. Private Sub Form_Load()
    11.     WebBrowser1.Navigate "www.google.com"
    12. End Sub
    13.  
    14. Private Sub Form_Unload(Cancel As Integer)
    15.    Set HTML = Nothing
    16. End Sub
    17. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, _
    18.                                                  URL As Variant)
    19.    Set HTML = WebBrowser1.Document
    20. End Sub
    Might be bringing an old post back alive but I definately needed help with this. The above code got me started on making my own context menu for the webbrowser control. However, My webbrowser control page that it navigates to has an iframe. When I right click on the iframe it does not keep the contextmenu, is there a way to fix this?

    Thanks,
    n3m.

  37. #77
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Webbrowser Control Tip and Examples

    So, does you example work with IFrames?


    Nevermind, I see now you stated that. BTW: I have been working on that problem from your other thread and so far no luck but I am sticking with it since I have learned a few things about frames and things since then so maybe, just maybe, I might be able to figure it iut.

  38. #78
    New Member
    Join Date
    Nov 2008
    Posts
    2

    Re: Webbrowser Control Tip and Examples

    Hi. Is there anyway any to get "updated" html code on pages with AJAX? Im working with .net 2008, Webbrowser.
    Is there any workarround to solve this?
    Thanks.
    Ariel

  39. #79
    Hyperactive Member JazzBass's Avatar
    Join Date
    Jun 1999
    Posts
    393

    Re: Webbrowser Control Tip and Examples

    Hi all,

    Thanks for the control tips and examples. I'm developing an Outlook-Addin in VB6 and I'm trying to do what is outlined in 'Making page on startup' as listed below. I'm retriving HTML from a database and would like to display it in the webbrowser control.

    Code:
          Private Sub Form_Load()
              WebBrowser1.Navigate "about:blank"
          End Sub
          Private Sub Command1_Click()
              Dim HTML As String
                  '----------The HTML CODE GOES FROM HERE AND DOWN----------
              HTML = "<HTML>" & _
                      "<TITLE>Page On Load</TITLE>" & _
                      "<BODY>" & _
                      "<FONT COLOR = BLUE>" & _
                      "This is a " & _
                      "<FONT SIZE = 5>" & _
                      "<B>" & _
                      "programmatically " & _
                      "</B>" & _
                      "</FONT SIZE>" & _
                      "made page" & _
                      "</FONT>" & _
                      "</BODY>" & _
                      "</HTML>"
                      '----------The HTML CODE GOES HERE AND ABOVE----------
              WebBrowser1.Document.Write HTML
          End Sub
    The problem is that I have no intellisense past WebBrowser1.Document (no .Write). and when I add it, the program errors out.

    I have a reference to the Microsoft Internet Controls, but I don't know what is the matter.

    Any help would be appreciated.

    Thanks,
    JB
    JazzBass
    In the .NET era
    Trying to remember VB6
    Progress:
    XP Professional @ Home
    and @ the Office

  40. #80
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Webbrowser Control Tip and Examples

    Here's 2 additions:
    Requires MSHTML Object Library and the WebBrowser is called wbMain

    Waiting for a webpage to load
    Code:
    cNavAndWait
    vb Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetTickCount Lib "kernel32.dll" () As Long
    4. Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    5.  
    6. Private m_bDOMReady        As Boolean
    7. Private WithEvents m_ctlWB As WebBrowser
    8.  
    9. Public Function navigateAndWait(ByVal ctlWebBrowser As WebBrowser, ByRef vData As Variant, Optional ByRef lMaxWaitTimeMillis As Long = 45000) As Boolean
    10.     On Error GoTo EH
    11.     Dim lEndTime As Long, obj As IHTMLElement, szURL As String
    12.    
    13.     '--Navigate and wait for the web page to load
    14.     '--vData can be a string(url) or an HTML Object
    15.    
    16.     Set m_ctlWB = ctlWebBrowser
    17.    
    18.     If (IsObject(vData)) Then
    19.         Set obj = vData
    20.         Select Case UCase(obj.tagName)
    21.             '--Hyperlink reference, like links on a page
    22.             Case "A"
    23.                 Call ctlWebBrowser.Navigate(obj.href)
    24.            
    25.             '--Forms, like login pages
    26.             Case "FORM"
    27.                 Call obj.submit
    28.                
    29.             '--Something else, so try to click it
    30.             Case Else
    31.                 Call obj.Click
    32.         End Select
    33.     Else
    34.         '--Regular URL
    35.         szURL = CStr(vData)
    36.         Call ctlWebBrowser.Navigate(szURL)
    37.     End If
    38.    
    39.     lEndTime = (GetTickCount() + lMaxWaitTimeMillis)
    40.     m_bDOMReady = False
    41.     Do While (Not m_bDOMReady)
    42.         '--Check for timeout
    43.         If ((lMaxWaitTimeMillis <> -1) And (GetTickCount() > lEndTime)) Then Exit Do
    44.         '--So app doesnt freeze
    45.         DoEvents
    46.         '--Dont kill the CPU
    47.         Call Sleep(5)
    48.     Loop
    49.     If (Not m_bDOMReady) Then
    50.         Call m_ctlWB.Stop
    51.     End If
    52.     Set m_ctlWB = Nothing
    53.    
    54.     navigateAndWait = (m_bDOMReady)
    55.     Exit Function
    56.    
    57. EH:
    58.     Call Err.Clear
    59.     navigateAndWait = False
    60. End Function
    61.  
    62. Private Sub m_ctlWB_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    63.     On Error GoTo EH
    64.     Dim oHTMLDoc As HTMLDocument
    65.    
    66.     '--In pages with no frames, this event fires one time after loading is complete.
    67.     '--In pages where multiple frames are loaded, this event fires for each frame where the DWebBrowserEvents2::DownloadBegin event has fired.
    68.     '--The top-level frame fires the DocumentComplete in the end.
    69.     '--So, to check if a page is done downloading, you need to check if the IDispatch* parameter, is same as the IDispatch of the WebBrowser control.
    70.    
    71.     If (pDisp Is m_ctlWB.object) Then
    72.         m_bDOMReady = True
    73.     ElseIf (TypeOf pDisp.Container Is HTMLDocument) Then
    74.         Set oHTMLDoc = pDisp.Container
    75.         If (oHTMLDoc.frames.length = 0) Then
    76.             m_bDOMReady = True
    77.         End If
    78.     End If
    79.     Exit Sub
    80.    
    81. EH: Call Err.Clear
    82. End Sub

    Example:
    vb Code:
    1. Private Sub cmdGo_Click()
    2.     Dim oNAW As cNavAndWait, sStart As Single
    3.    
    4.     Set oNAW = New cNavAndWait
    5.     sStart = Timer()
    6.     Call oNAW.navigateAndWait(wbMain, txtURL.Text)
    7.     Call MsgBox(txtURL.Text + " took " + CStr(Timer() - sStart) + " seconds to load.", vbOKOnly Or vbInformation, "Navigate And Wait")
    8.     Set oNAW = Nothing
    9. End Sub




    How to copy and save an image from a webpage
    vb Code:
    1. Option Explicit
    2.  
    3. Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    4.  
    5. Private m_bDOMRdy As Boolean
    6.  
    7. Private Sub cmdCopy_Click()
    8.     Dim pDoc As HTMLDocument, pImgEle As IHTMLImgElement, pCR As IHTMLControlRange, szImgname As String
    9.    
    10.     '--Grab the image of the first picture on the page and copy it into the PictureBox
    11.     Set pDoc = wbMain.Document
    12.     For Each pImgEle In pDoc.All.tags("IMG")
    13.         szImgname = Mid(pImgEle.src, InStrRev(pImgEle.src, "/") + 1)
    14.        
    15.         '--Create a control range
    16.         '--MSDN: Contains a range of control type elements that is used for control selection; _
    17.                  and represents an array of controls that can be operated on as a group.
    18.         Set pCR = pDoc.body.createControlRange()
    19.         '--Clear the clipboard
    20.         Call Clipboard.Clear
    21.         '--Add the image element
    22.         Call pCR.Add(pImgEle)
    23.         '--Copy it to the clipboard
    24.         Call pCR.execCommand("copy")
    25.         '--Do what you want with the image since its on the clipboard
    26.         Set pbPic.Picture = Clipboard.GetData(vbCFBitmap)
    27.         '--Save the image
    28.         Call SavePicture(pbPic.Picture, "C:\" + szImgname)
    29.        
    30.         Exit For
    31.     Next pImgEle
    32. End Sub
    33.  
    34. Private Sub Form_Load()
    35.     m_bDOMRdy = False
    36.     Call wbMain.Navigate("http://frontrowcrew.com/")
    37.     Do While (Not m_bDOMRdy)
    38.         DoEvents
    39.         Call Sleep(10)
    40.     Loop
    41. End Sub
    42.  
    43. Private Sub wbMain_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    44.     If (pDisp Is wbMain.Object) Then
    45.         m_bDOMRdy = True
    46.     End If
    47. End Sub

Page 2 of 4 FirstFirst 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width