Webbrowser control with internet transfer control

Posted on 2004-10-12
Last Modified: 2012-05-05
If I use the internet transfer control to download a webpage, then use the open, write and close methods to insert the html into a webbrowser control, is there a way to also insert the cookies so that when links are clicked on in the webbrowser control the cookies will carry through?

I'm trying to find a way to use the webbrowser control to turn off images for a particular instance of the webbrowser control only and only for certain pages.  I thought this might be a way that I could accomplish it.

Here's another thread that uses a different route to solve the problem.  This method would be using the internet transfer control if it's possible.

The link below is the other, what I believe to be more difficult method.

Please note that changing the registry item for not downloading images isn't possible since my program will be running while browsers are running and we can't have all browsers not downloading images.  Only the webbrowser instance for the webbrowser control.
Question by:jodyglidden
  • 3
LVL 17

Accepted Solution

zzzzzooc earned 500 total points
ID: 12294928
If the Inet control returns any cookies, you can parse them and set them through the WebBrowser as shown below.

Private Sub Command1_Click()
    'Get the current cookies...
    Call MsgBox(WebBrowser1.Document.cookie)
    'Add a cookie...
    WebBrowser1.Document.cookie = "name=1"
    'Get the new cookies to see our addition...
    Call MsgBox(WebBrowser1.Document.cookie)
    'Change the cookie we just added...
    WebBrowser1.Document.cookie = "name=2"
    'Get the new cookies to see our modification...
    Call MsgBox(WebBrowser1.Document.cookie)
End Sub
Private Sub Form_Load()
    WebBrowser1.Navigate ""
End Sub

There may be an issue with that, however. Since you're writing out the html for certain sites without being at the actual domain, I don't believe the cookie(s) you use will belong to that domain so IE may not send them (I'm not sure though). You can alternatively send the cookies for each link the person goes to as shown below.

Private Sub Form_Load()
    WebBrowser1.Navigate ""
End Sub
Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
    'if no headers were sent.. cancel and send our headers (cookie(s))
    If Headers = vbNullString Then
        Cancel = True
        WebBrowser1.Navigate "", , , , "your cookie(s) here"
    End If
End Sub

>> The link below is the other, what I believe to be more difficult method.
More difficult? It seems like "extremely more difficult" instead. :) You may be better off just removing all of the IMG elements from the DOM before they're displayed.
LVL 17

Expert Comment

ID: 12307728
Seeing as the other question is resolved, you probably don't need this answered anymore. Feel free to post in Community Support asking for this to be PAQ'd and points refunded. I'll agree to that.

Author Comment

ID: 12307741
Ahh, it's fine for me.  Here you go.
LVL 17

Expert Comment

ID: 12307800
.. didn't need to. Thanks though. :)

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Determine Range to Select 5 56
Access query that references subform 5 48
How to measure sizes and angles in scanned images ? 3 87
transition to visual .net from vb6 5 59
Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 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