Results 1 to 17 of 17

Thread: I dont want WebBrowser to download the images

  1. #1

    Thread Starter
    Banned
    Join Date
    Feb 2001
    Location
    Back to sh*tland
    Posts
    294

    I dont want WebBrowser to download the images

    How can I do it?

  2. #2

    Thread Starter
    Banned
    Join Date
    Feb 2001
    Location
    Back to sh*tland
    Posts
    294
    Is it possible btw?

  3. #3

    Thread Starter
    Banned
    Join Date
    Feb 2001
    Location
    Back to sh*tland
    Posts
    294
    I'll investigate.
    Thanks for the tip, now I know what I should be looking for.

  4. #4
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    I have a method, but it involves shelling the "Internet Options" control panel, and then using Sendkeys to check or uncheck the "Show Pictures" option under the Advanced tab.

    Actually all that does is change a setting in the registry. You could try changing the setting, I'm not sure what registry key it is. It's under Internet Explorer...that much I know. If I remember right changing this setting in the registry didn't work for me, that's why I had to do it the hard way by shelling "Internet Options" control panel.

    If you want the code for shelling the control panel let me know....I'll dig it up.

  5. #5
    Hyperactive Member
    Join Date
    Apr 2001
    Posts
    315
    You are in luck. Take a hatchet to it.
    Code:
    Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
      With WebBrowser1
          lblAddress.Caption = Now & " " & " State=" & .ReadyState & " " & Text
      End With
        Select Case WebBrowser1.ReadyState
        Case READYSTATE_INTERACTIVE
            Handler.DropImages
        End Select
        
    End Sub
    'Class already has Document object
    Public Sub DropImages()
        '*****
        '* Kill all IMGs for faster loading.
        '* We don't need no stinking pictures.
        '*****
        Dim objElements      As Object
        Dim objElement      As Object
        Dim I               As Long
        
        Do
            If Len(mstrDownload) = 0 Then Exit Do ' in case manual
            If mobjDocument Is Nothing Then Exit Do
               
            On Error Resume Next
            Set objElements = mobjDocument.getElementsByTagName("IMG")
            If Err.Number <> 0 Then Exit Do
            If objElements Is Nothing Then Exit Do
            For I = objElements.length - 1 To 0 Step -1 ' Delete backwards
                Set objElement = objElements.Item(I)
                If Err.Number <> 0 Then Exit Do
                If objElement Is Nothing Then Exit Do
                If LCase(objElement.tagName) = "img" Then
                    objElement.outerHTML = ""
                End If
            Next
        Exit Do: Loop
        
    End Sub

  6. #6
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    John -

    Your code looks good, but there are a few things missing. I tried running it as is, and recieved an error: object required - highlighting "Handler.DropImages". I also notice that you didn't declare "mobjDocument", and what is "mstrDownload". One last thing does one need to reference the HTML Object library?

    Sorry if it sounds like I'm being picky, I'm not. I'd like to try this code out, but there is just too much missing for me to try and put 2 and 2 together. Could you clean it up a little, I know this would help me an others to understanding and using it.

    Thanks...

  7. #7
    Hyperactive Member
    Join Date
    Apr 2001
    Posts
    315
    Ok, I converted it from a class method to an ordinary sub.
    mobjDocument was an Instance (Module) level varable already set to the document. Handler was an object containing the class. See, I am using one form for multiple navigations. I have to get through five forms for sign-on before I can ask for payload.
    Code:
    Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
      With WebBrowser1
          lblAddress.Caption = Now & " " & " State=" & .ReadyState & " " & Text
      End With
        Select Case WebBrowser1.ReadyState
        Case READYSTATE_INTERACTIVE
            DropImages WebBrpwser.Document
        End Select
        
    End Sub
    Public Sub DropImages(mobjDocument as HTMLDocument)
        '*****
        '* Kill all IMGs for faster loading.
        '* We don't need no stinking pictures.
        '*****
        Dim objElements      As Object ' Use objects instead of specific
        Dim objElement      As Object
        Dim I               As Long
        
        Do
            If Len(mstrDownload) = 0 Then Exit Do ' in case manual
            If mobjDocument Is Nothing Then Exit Do
               
            On Error Resume Next
            Set objElements = mobjDocument.getElementsByTagName("IMG")
            If Err.Number <> 0 Then Exit Do
            If objElements Is Nothing Then Exit Do
            For I = objElements.length - 1 To 0 Step -1 ' Delete backwards
                Set objElement = objElements.Item(I)
                If Err.Number <> 0 Then Exit Do
                If objElement Is Nothing Then Exit Do
                If LCase(objElement.tagName) = "img" Then
                    objElement.outerHTML = ""
                End If
            Next
        Exit Do: Loop
        
    End Sub

  8. #8
    Hyperactive Member
    Join Date
    Apr 2001
    Posts
    315
    Here is an example of handing a form of "Redirection" I ran into plus not reacting to documentComplete for frames. I use the event model of the webbrowser rather than DoEvents on webbrowser.busy. Fewer problems in the long-run.
    Code:
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        ' Process if whole page is done not just a frame
        If Not (pDisp Is WebBrowser1.object) Then Exit Sub
        
        '*****
        '* Reday State must be interactive or complete
        '*****
        Select Case WebBrowser1.ReadyState
        Case READYSTATE_INTERACTIVE, READYSTATE_COMPLETE
            Handler.DocumentComplete
        End Select
            
    End Sub
    '--------------------------- Class Method
    
    
    
    
    Public Sub DocumentComplete()
        Dim objElements     As Object
        Dim objElement      As Object
        Dim strBody         As String
        Dim blnBusy         As Boolean
        
        Set mobjDocument = mobjWeb.Document
        blnBusy = False
        Do
            With mobjWeb
                
                Set mobjDocument = mobjWeb.Document
                If Err.Number <> 0 Then Exit Do
                If mobjDocument Is Nothing Then Exit Do
        
                '*****
                '* META http-equiv="Refresh" BYPASS REDIRECTION
                '*****
                Set objElements = mobjDocument.getElementsByTagName("Meta")
                If Err.Number <> 0 Then Exit Do
                If objElements Is Nothing Then Exit Do
                For Each objElement In objElements
                    If LCase(objElement.httpEquiv) = "refresh" Then
                        '* We are still busy
                        blnBusy = True
                        Exit Do
                    End If
                Next
                If Err.Number <> 0 Then Exit Do
        
                '*****
                '* CallByName Page Processor
                '*****
                Dim strDownLoad     As String
                strDownLoad = mstrDownload
                mstrDownload = ""
                If Len(strDownLoad) > 0 Then
                    CallByName Me, strDownLoad, VbMethod
                    '*****
                    '* Are we still running
                    '****
                    If Len(mstrDownload) > 0 Then
                        blnBusy = True
                    ElseIf mblnAutoRunMode = True Then
                        Quit
                    End If
                End If
            End With
        Exit Do: Loop
        mblnBusy = blnBusy
    End Sub
    Last edited by John Yingling; Jun 30th, 2001 at 11:28 AM.

  9. #9
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    This looks like good stuff.....unfortunately I can't get it to work. I have made a reference to the HTML object library, but your code for removing images doesn't seem to work for me. Here's what I have. You'll notice I have corrected your typo where you call the DropImages Sub. As far as your other code, The name of the Sub "DocumentComplete" has me a little confused. Is this Sub the DocumentComplete Event of a WBC, or is this a Sub that gets called, and if it does where would you call it?

    One last thing, I have looked all over for information on the various Classes of the MSHTML library, but have found very little info. What is it that you use for reference (a book perhaps) for this library?

    VB Code:
    1. Private Sub Form_Load()
    2.     WebBrowser1.Navigate "http://www.yahoo.com"
    3. End Sub
    4.  
    5. Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
    6.   With WebBrowser1
    7.       lblAddress.Caption = Now & " " & " State=" & .ReadyState & " " & Text
    8.   End With
    9.     Select Case WebBrowser1.ReadyState
    10.     Case READYSTATE_INTERACTIVE
    11.         DropImages WebBrowser1.Document
    12.     End Select
    13.    
    14. End Sub
    15. Public Sub DropImages(mobjDocument As HTMLDocument)
    16.     '*****
    17.     '* Kill all IMGs for faster loading.
    18.     '* We don't need no stinking pictures.
    19.     '*****
    20.     Dim objElements      As Object ' Use objects instead of specific
    21.     Dim objElement      As Object
    22.     Dim I               As Long
    23.    
    24.     Do
    25.         If Len(mstrDownload) = 0 Then Exit Do ' in case manual
    26.         If mobjDocument Is Nothing Then Exit Do
    27.            
    28.         On Error Resume Next
    29.         Set objElements = mobjDocument.getElementsByTagName("IMG")
    30.         If Err.Number <> 0 Then Exit Do
    31.         If objElements Is Nothing Then Exit Do
    32.         For I = objElements.length - 1 To 0 Step -1 ' Delete backwards
    33.             Set objElement = objElements.Item(I)
    34.             If Err.Number <> 0 Then Exit Do
    35.             If objElement Is Nothing Then Exit Do
    36.             If LCase(objElement.tagName) = "img" Then
    37.                 objElement.outerHTML = ""
    38.             End If
    39.         Next
    40.     Exit Do: Loop
    41.    
    42. End Sub

  10. #10
    Hyperactive Member
    Join Date
    Apr 2001
    Posts
    315
    I removed the reference to mstrDownload. What does not work?
    As far as DocumentComplete, yes it is called from DocumentComplete in the Webbrowser. You are going to have learn enough to pull out of examples what you need. If you do not have a lblAddress then put it on your form in so you can see what is happenning. I am stll "in process" after two weeks of full-time learning and doing. Somethings have to be tried without full knowledge. I didn't think or learn about redirection until I saw it.
    Use your View Source. or at documentcomplete have a multiline textbox with scrollbars and do text1.text = webbrowser.document.documentelement.outerHTML and look at it.
    I use
    http://www.w3.org/TR/REC-DOM-Level-1...-one-html.html
    (read it all)
    http://msdn.microsoft.com MSDN / Web Development / Programming and Reusing the Browser and and
    O'REILLY Dynamic HTML. (but not much).
    Code:
    Private Sub Form_Load()
        WebBrowser1.Navigate "http://www.yahoo.com"
    End Sub
    
    Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
      With WebBrowser1
          lblAddress.Caption = Now & " " & " State=" & .ReadyState & " " & Text
      End With
        Select Case WebBrowser1.ReadyState
        Case READYSTATE_INTERACTIVE
            DropImages WebBrowser1.Document
        End Select
        
    End Sub
    Public Sub DropImages(mobjDocument As HTMLDocument)
        '*****
        '* Kill all IMGs for faster loading.
        '* We don't need no stinking pictures.
        '*****
        Dim objElements      As Object ' Use objects instead of specific
        Dim objElement      As Object
        Dim I               As Long
        
        Do
            If mobjDocument Is Nothing Then Exit Do
               
            On Error Resume Next
            Set objElements = mobjDocument.getElementsByTagName("IMG")
            If Err.Number <> 0 Then Exit Do
            If objElements Is Nothing Then Exit Do
            For I = objElements.length - 1 To 0 Step -1 ' Delete backwards
                Set objElement = objElements.Item(I)
                If Err.Number <> 0 Then Exit Do
                If objElement Is Nothing Then Exit Do
                If LCase(objElement.tagName) = "img" Then
                    objElement.outerHTML = ""
                End If
            Next
        Exit Do: Loop
        
    End Sub

  11. #11
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Hey Thanks!, it's working now. I didn't notice mstrDownload was still in there. That's what the problem was, but now it is working. Thanks for the links, I'm familar with some of them. I thought you might be working out of, or referencing a book that's why I asked.

    This gives me a few ideas. One of them is removing IFRAMES, which are usually used for advertising. I should be able to adapt your "removing images" code for this. Thanks again for the code.

  12. #12
    Member
    Join Date
    Jul 2000
    Posts
    35
    It's a bit for answering to this topic, but I want to kill the images and I get the message "User defined type not defined" with VB highlighting "Public Sub DropImages(mobjDocument As HTMLDocument)". How do I get past this error?

    Thanks,

  13. #13
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    You need to make a reference to the MSHTML.tlb
    (Microsoft HTML Object Library)

  14. #14
    Member
    Join Date
    Jul 2000
    Posts
    35
    Er, thanks, but how do I do that (in code)?

    Thanks again,

  15. #15
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    It's not something you do in code. It's a setting that you make in VB. I can't remember off-hand what menu it is under. It's under the same menu....where you add a component, if that helps. Find it in the menu at the top, then click on References, and scroll down until you find "Microsoft HTML Object Library". Then check the box......you've just made a reference.

    Hope that helps...

  16. #16
    Hyperactive Member
    Join Date
    Apr 2001
    Posts
    315
    You can can change As HTMLDocument to As Object. This will then work regardless of the IE version i.e. use "late binding".

  17. #17
    Member
    Join Date
    Jul 2000
    Posts
    35
    Thanks Bloodeye, it did help and now it works, it was under the Project Menu.
    And thanks John for replying,

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