Webbrowser control with internet transfer control

Posted on 2004-10-12
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 17

Accepted Solution

zzzzzooc earned 1500 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 "http://www.google.com"
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 "http://www.google.com"
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 "www.yahoo.com", , , , "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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

764 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