WebBrowser control issues

I am using the webcontrol, but having some general issues. I enjoy using the webcontrol for its functions, such as grabbing links very easily out..

Issue is, the webbrowser acts 'like' a browser. So it directs me to pages if theres a redirect, or a popup appears for example. All I really want it for is it's functions, and to be able to view the source code. Everything else, like redirecting, and popup shoudn't happen. Technically I want it to open like you open up notepad to view the source, then edit it at will (Using automated coding)..

Generally my program goes through and checks each link, and asks you to change the anchor text. It works fine, cept when theres popups or a redirect, then it messes up because its trying to actually 'go' to that page when instead I want the file open just for viewing source and for its easy to use functions...

Is there any way to solve this? Possibly another component too do this? I enjoy things like 'For Each HTMLlinks In HTMLDOC.links' to grab links and other things like that.. That is why I want to use it. I think it might be difficult to do this otherwise..

Thank you very much!
LVL 7
VallerianiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VallerianiAuthor Commented:
Just posting again..

Would there be any better control that can handle it, to edit source code as easy? Without the hassle of it using activex, loading flash, etc.. Just simply like 'viewing source code' without it loading anything from the page.
0
dentabCommented:
You can download source very easily using IE api... hang on
0
dentabCommented:
Try the code below in a module

msgbox posturl("http://localhost", "")

or

msgbox posturl("http://localhost?getvar=test", "postvar=testtoo!")

Private Const aspivPort As Long = 80
 
Const INTERNET_SERVICE_HTTP = 3
 
'Public DontUseCache As Boolean
 
Private Enum InfoLevelEnum
    HTTP_QUERY_CONTENT_TYPE = 1
    HTTP_QUERY_CONTENT_LENGTH = 5
    HTTP_QUERY_EXPIRES = 10
    HTTP_QUERY_LAST_MODIFIED = 11
    HTTP_QUERY_PRAGMA = 17
    HTTP_QUERY_VERSION = 18
    HTTP_QUERY_STATUS_CODE = 19
    HTTP_QUERY_STATUS_TEXT = 20
    HTTP_QUERY_RAW_HEADERS = 21
    HTTP_QUERY_RAW_HEADERS_CRLF = 22
    HTTP_QUERY_FORWARDED = 30
    HTTP_QUERY_SERVER = 37
    HTTP_QUERY_USER_AGENT = 39
    HTTP_QUERY_SET_COOKIE = 43
    HTTP_QUERY_REQUEST_METHOD = 45
    HTTP_STATUS_DENIED = 401
    HTTP_STATUS_PROXY_AUTH_REQ = 407
End Enum
 
Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const INTERNET_OPEN_TYPE_DIRECT = 1
Private Const INTERNET_OPEN_TYPE_PROXY = 3
 
'Private Const SCUSERAGENT = "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 5.1)"
Private Const SCUSERAGENT = "TABUSB"
Private Const INTERNET_FLAG_RELOAD = &H80000000
Private Const INTERNET_FLAG_ASYNC = &H10000000  ' this request is asynchronous (where supported)
 
Private Const INTERNET_FLAG_FROM_CACHE = &H1000000   ' use offline semantics
Private Const INTERNET_FLAG_OFFLINE = INTERNET_FLAG_FROM_CACHE
Private Const INTERNET_FLAG_EXISTING_CONNECT = &H20000000
 
Private Declare Function HttpQueryInfo Lib "wininet.dll" Alias "HttpQueryInfoA" _
    (ByVal hHttpRequest As Long, ByVal lInfoLevel As Long, ByRef sBuffer As Any, _
    ByRef lBufferLength As Long, ByRef lIndex As Long) As Integer
 
 
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
    (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, _
    ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
 
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" _
    (ByVal hOpen As Long, ByVal sUrl As String, ByVal sHeaders As String, _
    ByVal lLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
 
Private Declare Function InternetReadFile Lib "wininet.dll" _
    (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, _
    lNumberOfBytesRead As Long) As Integer
 
Private Declare Function InternetCloseHandle Lib "wininet.dll" _
    (ByVal hInet As Long) As Integer
 
Private Declare Function HttpSendRequest Lib "wininet.dll" Alias "HttpSendRequestA" ( _
    ByVal hHttpRequest As Long, _
    ByVal lpszHeaders As String, _
    ByVal dwHeadersLength As Long, _
    ByVal lpOptional As String, _
    ByVal dwOptionalLength As Long) As Boolean
    
Private Declare Function HttpOpenRequest Lib "wininet.dll" Alias "HttpOpenRequestA" ( _
    ByVal hHttpSession As Long, _
    ByVal lpszVerb As String, _
    ByVal lpszObjectName As String, _
    ByVal lpszVersion As String, _
    ByVal lpszReferer As String, _
    ByVal lpszAcceptTypes As String, _
    ByVal dwFlags As Long, _
    ByVal dwContext As Long) As Long
    
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" ( _
    ByVal hInternetSession As Long, _
    ByVal lpszServerName As String, _
    ByVal nServerPort As Integer, _
    ByVal lpszUsername As String, _
    ByVal lpszPassword As String, _
    ByVal dwService As Long, _
    ByVal dwFlags As Long, _
    ByVal dwContext As Long) As Long
    
Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" _
    (lpdwError As Long, ByVal lpszBuffer As String, ByVal lpdwBufferLength As Long) As Integer
    
' Adds one or more HTTP request headers to the HTTP request handle.
Private Declare Function HttpAddRequestHeaders Lib "wininet.dll" Alias "HttpAddRequestHeadersA" _
(ByVal hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, _
ByVal lModifiers As Long) As Integer
' Flags to modify the semantics of this function. Can be a combination of these values:
' Adds the header only if it does not already exist; otherwise, an error is returned.
Const HTTP_ADDREQ_FLAG_ADD_IF_NEW = &H10000000
' Adds the header if it does not exist. Used with REPLACE.
Const HTTP_ADDREQ_FLAG_ADD = &H20000000
' Replaces or removes a header. If the header value is empty and the header is found,
' it is removed. If not empty, the header value is replaced
Const HTTP_ADDREQ_FLAG_REPLACE = &H80000000
 
 
    
Public Function PostUrl(ByVal sUrl As String, ByVal strPostData As String) As String
  Dim bRes As Boolean
  Dim hrequest As Long
  Dim strbuffer As String * 1
  Dim returnData As String
  Dim hConnect As Long
  Dim hInternet As Long
  Dim lBytesRead As Long
  Dim sHost As String
  Dim oStrB As clsStringBuilder
  Set oStrB = New clsStringBuilder
 
  While InStr(sUrl, "://")
    sUrl = Mid(sUrl, InStr(sUrl, "://") + 3)
  Wend
  
  sHost = sUrl
  
  While InStr(sHost, "/")
    sHost = Left(sHost, InStr(sHost, "/") - 1)
  Wend
  
  sUrl = Mid(sUrl, Len(sHost) + 1)
  
  While InStr(sHost, ":")
    sHost = Left(sHost, InStr(sHost, ":") - 1)
  Wend
  'Stop
  
  hInternet = InternetOpen(App.Title, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
  hConnect = InternetConnect(hInternet, sHost, aspivPort, "", "", INTERNET_SERVICE_HTTP, 0, 0)
 
 
  If strPostData = "" Then
    hrequest = HttpOpenRequest(hConnect, "GET", sUrl, "HTTP/1.0", vbNullString, vbNullString, 0, 0)
  Else
    hrequest = HttpOpenRequest(hConnect, "POST", sUrl, "HTTP/1.0", vbNullString, vbNullString, 0, 0)
  End If
  Call HttpAddRequestHeaders(hrequest, "Content-Type: application/x-www-form-urlencoded", Len("Content-Type: application/x-www-form-urlencoded"), HTTP_ADDREQ_FLAG_REPLACE Or HTTP_ADDREQ_FLAG_ADD)
  Call HttpAddRequestHeaders(hrequest, "BrowserHost: " & SCUSERAGENT, Len("BrowserHost: " & SCUSERAGENT), HTTP_ADDREQ_FLAG_REPLACE Or HTTP_ADDREQ_FLAG_ADD)
 
  bRes = HttpSendRequest(hrequest, vbNullString, 0, strPostData, Len(strPostData))
  'returnData = ""
  oStrB.Clear
  Do
    bRes = InternetReadFile(hrequest, strbuffer, Len(strbuffer), lBytesRead)
    If lBytesRead > 0 Then
      oStrB.addDataFast strbuffer
      '  returnData = returnData + strbuffer
    End If
  Loop While lBytesRead > 0
  PostUrl = oStrB.StringStored
  Set oStrB = Nothing
  DoEvents
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VallerianiAuthor Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.