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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

947 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now