WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Dialog Boxes

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Web Browser Control

Keywords: 	 Web Browser Control

;
;TITLE    : dos.wbt
;DATE     : 27 Août 2002
;AUTHOR   : Delgove Jean-Jacques
;VERSION  : 1.0
;UPDATED  :
;PURPOSE  : scan html page with ole winbatch
;----------------------------------------------------------------------------
;  HEX2DEC : convert hexa value to decimal
;----------------------------------------------------------------------------
#DefineFunction Hex2Dec(hex)
	str="0123456789ABCDEF"
	hex=StrTrim(StrUpper(hex))
	hexlen=StrLen(hex)
	dec=0
	for x=1 to hexlen
		dec=(dec*16) + StrIndex(str,strsub(hex,x,1),0,@fwdscan) -1
	next
	return(dec)
#EndFunction
;----------------------------------------------------------------------------
; DEC2HEX : convert decimal value to hexa
;----------------------------------------------------------------------------
#DefineFunction Dec2Hex(dec)
	str="0123456789ABCDEF"
	hex1=""
	hex=""
	d=dec
	while d >0
		d1=d mod 16
		d=d/16	
		hex1=strcat(hex1,strsub(str,d1+1,1))
	endwhile
	i=strlen(hex1)
	while (i >=1)
		hex=strcat(hex,strsub(hex1,i,1))
		i=i-1
	endwhile
	return(hex)
#EndFunction
;----------------------------------------------------------------------------
; GetFormNumberControl : get number of controls of form number Id
;----------------------------------------------------------------------------
#DefineFunction GetFormNumberControl(browser,Id)
    ret=0
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.forms
    ind=0
    if( b2 !=0) then
        l=b2.length - 1
    	if ( Id <= l) then
    		form=BrowserDoc.forms(%Id%)
		x = form.elements
        	ret = x.length
		ObjectClose(form)
		ObjectClose(x)
    	endif    	
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return ret
#EndFunction
;----------------------------------------------------------------------------
; GetFormControlName : get name of control number icontrol of form number Id
;----------------------------------------------------------------------------
#DefineFunction GetFormControlName(browser,Id,icontrol)
    name=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.forms
    ind=0
    if( b2 !=0) then
        l=b2.length - 1
    	if ( Id <= l) then
    		form=BrowserDoc.forms(%Id%)
		x = form.elements
        	i = x.length -1
        	if( icontrol <= i) then
        		z = form.elements(icontrol)
        		name=z.name
        		ObjectClose(z)
        	endif
		ObjectClose(form)
		ObjectClose(x)		
    	endif   	
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return name
#EndFunction
;----------------------------------------------------------------------------
; GetFormControlId : get Id of control number icontrol of form number Id
;----------------------------------------------------------------------------
#DefineFunction GetFormControlId(browser,Id,icontrol)
    idd=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.forms
    ind=0
    if( b2 !=0) then
        l=b2.length - 1
    	if ( Id <= l) then
    		form=BrowserDoc.forms(%Id%)
		x = form.elements
        	i = x.length -1
        	if( icontrol <= i) then
        		z = form.elements(icontrol)
        		idd=z.id
        		ObjectClose(z)
        	endif
		ObjectClose(form)
		ObjectClose(x)		
    	endif   	
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return idd
#EndFunction
;----------------------------------------------------------------------------
; GetFormControlType : get type of control number icontrol of form number Id
;----------------------------------------------------------------------------
#DefineFunction GetFormControlType(browser,Id,icontrol)
    type=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.forms
    ind=0
    if( b2 !=0) then
        l=b2.length - 1
    	if ( Id <= l) then
    		form=BrowserDoc.forms(%Id%)
		x = form.elements
        	i = x.length -1
        	if( icontrol <= i) then
        		z = form.elements(icontrol)
        		type=z.type
        		ObjectClose(z)
        	endif
		ObjectClose(form)
		ObjectClose(x)
    	endif    	
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return type
#EndFunction
;----------------------------------------------------------------------------
; GetFormControlValue : get value of control number icontrol of form number Id
;----------------------------------------------------------------------------
#DefineFunction GetFormControlValue(browser,Id,icontrol)
    value=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.forms
    ind=0
    if( b2 !=0) then
        l=b2.length - 1
    	if ( Id <= l) then
    		form=BrowserDoc.forms(%Id%)
		x = form.elements
        	i = x.length -1
        	if( icontrol <= i) then
        		z = form.elements(icontrol)
        		value=z.value
        		ObjectClose(z)
        	endif
		ObjectClose(form)
		ObjectClose(x)
    	endif   	
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return value
#EndFunction
;----------------------------------------------------------------------------
; GetFormAction : get action of form number Id
;----------------------------------------------------------------------------
#DefineFunction GetFormAction(browser,Id)
    action=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.forms
    ind=0
    if( b2 !=0) then
        l=b2.length - 1
    	if ( Id <= l) then
    		form=BrowserDoc.forms(%Id%)
    		action=form.action
		ObjectClose(form)	
    	endif    	
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return action
#EndFunction
;----------------------------------------------------------------------------
; GetFormTarget : get target of form number Id
;----------------------------------------------------------------------------
#DefineFunction GetFormTarget(browser,Id)
    target=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.forms
    ind=0
    if( b2 !=0) then
        l=b2.length - 1
    	if ( Id <= l) then
    		form=BrowserDoc.forms(%Id%)
    		target=form.target
		ObjectClose(form)	
    	endif    	
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return target
#EndFunction
;----------------------------------------------------------------------------
; SetFormControlValue : set control icontrol of form Id to value
;----------------------------------------------------------------------------
#DefineFunction SetFormControlValue(browser,Id,icontrol,value) 
    ErrorMode(@OFF)  
    BrowserDoc = Browser.Document
    b2=BrowserDoc.forms
    ind=0
    if( b2 !=0) then
        l=b2.length - 1
    	if ( Id <= l) then
    		form=BrowserDoc.forms(%Id%)
		x = form.elements
        	i = x.length -1
        	if( icontrol <= i) then
        		z = form.elements(icontrol)
        		z.value = value
        		ObjectClose(z)
        	endif
		ObjectClose(form)
		ObjectClose(x)
    	endif    	
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
#EndFunction
;----------------------------------------------------------------------------
; GetFormMethod : get method of form Id 
;----------------------------------------------------------------------------
#DefineFunction GetFormMethod(browser,Id)
    method=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.forms
    ind=0
    if( b2 !=0) then
        l=b2.length - 1
    	if ( Id <= l) then
    		form=BrowserDoc.forms(%Id%)
		method=form.method
		ObjectClose(form)		
    	endif   	
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return method
#EndFunction
;----------------------------------------------------------------------------
; FormSubmit : submit  form Id 
;----------------------------------------------------------------------------
#DefineFunction FormSubmit(browser,Id)
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.forms
    ind=0
    if( b2 !=0) then
        l=b2.length - 1
    	if ( Id <= l) then
    		form=BrowserDoc.forms(%Id%)
		form.submit
		ObjectClose(form)		
    	endif   	
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
#EndFunction
;----------------------------------------------------------------------------
; GetTitle : get title of html page
;----------------------------------------------------------------------------
#DefineFunction GetTitle(browser)
    title=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    title=BrowserDoc.title
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return title
#EndFunction
;----------------------------------------------------------------------------
; GetTitle : get last modification time  of html page
;----------------------------------------------------------------------------
#DefineFunction GetLastModified(browser)
    LastModified=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    LastModified=BrowserDoc.LastModified
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return LastModified
#EndFunction
;----------------------------------------------------------------------------
; GetLinkColor : get color of link
;----------------------------------------------------------------------------
#DefineFunction GetLinkColor(browser)
    LinkColor=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    LinkColor=BrowserDoc.LinkColor
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return LinkColor
#EndFunction
;----------------------------------------------------------------------------
; GetStyleSheets : get style sheet objet
;----------------------------------------------------------------------------
#DefineFunction GetStyleSheets(browser)
    StyleSheets=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    StyleSheets=BrowserDoc.StyleSheets
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return StyleSheets
#EndFunction
;----------------------------------------------------------------------------
; SetLinkColor : set color of link
;----------------------------------------------------------------------------
#DefineFunction SetLinkColor(browser,color)
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    BrowserDoc.LinkColor=color
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
#EndFunction
;----------------------------------------------------------------------------
; vGetLinkColor : get color of visited link
;----------------------------------------------------------------------------
#DefineFunction GetVlinkColor(browser)
    vLinkColor=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    vLinkColor=BrowserDoc.vLinkColor
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return vLinkColor
#EndFunction
;----------------------------------------------------------------------------
; SetVlinkColor : set color of visitd link
;----------------------------------------------------------------------------
#DefineFunction SetVlinkColor(browser,color)
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    BrowserDoc.vLinkColor=color
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
#EndFunction
;----------------------------------------------------------------------------
; GetDomain : get domain 
;----------------------------------------------------------------------------
#DefineFunction GetDomain(browser)
    domain=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    domain=BrowserDoc.domain
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return domain
#EndFunction
;----------------------------------------------------------------------------
; GetUrl : get url
;----------------------------------------------------------------------------
#DefineFunction GetUrl(browser)
    url=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    url=BrowserDoc.url
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return url
#EndFunction
;----------------------------------------------------------------------------
; GetLocation : get location
;----------------------------------------------------------------------------
#DefineFunction GetLocation(browser)
    Location=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    Location=BrowserDoc.Location
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return Location
#EndFunction
;----------------------------------------------------------------------------
; GetCookie : get cookie
;----------------------------------------------------------------------------
#DefineFunction GetCookie(browser)
    cookie=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    Location=BrowserDoc.cookie
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return cookie
#EndFunction
;----------------------------------------------------------------------------
; GetFormName : get name of  form Id 
;----------------------------------------------------------------------------
#DefineFunction GetFormName(browser,Id)
    name=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.forms
    if( b2 !=0) then
        l=b2.length - 1
    	if ( Id <= l) then
    		form=BrowserDoc.forms(%Id%)
		name=form.name
		if(name == "") then name="_name%i%"
    	endif
    endif
    ObjectClose(BrowserDoc)
    ObjectClose(b2)
    ObjectClose(form)
    ErrorMode(@CANCEL)
    return name   
#EndFunction
;----------------------------------------------------------------------------
; GetHtml : get html page 
;----------------------------------------------------------------------------
#DefineFunction GetHtml(browser)
   html=""
   ErrorMode(@OFF)
   BrowserDoc = Browser.Document
   BrowserBody = BrowserDoc.Body
   BrowserPage = BrowserBody.CreateTextRange
   ; The HTML of the page
   BrowserPageHTML = BrowserPage.HTMLText
   html=BrowserPageHTML
   ObjectClose(BrowserDoc)
   ObjectClose(BrowserBody)
   ObjectClose(BrowserPage)
   ErrorMode(@CANCEL)
   return html
#EndFunction
;----------------------------------------------------------------------------
; GetText : get text of html page 
;----------------------------------------------------------------------------
#DefineFunction GetText(browser)
   text=""
   ErrorMode(@OFF)
   BrowserDoc = Browser.Document
   BrowserBody = BrowserDoc.Body
   BrowserPage = BrowserBody.CreateTextRange
   ; The HTML of the page
   BrowserPageText = BrowserPage.Text
   text=BrowserPageText
   ObjectClose(BrowserDoc)
   ObjectClose(BrowserBody)
   ObjectClose(BrowserPage)
   ErrorMode(@CANCEL)
   return text
#EndFunction
;----------------------------------------------------------------------------
; GetNumberForm : get number of forms of html page
;----------------------------------------------------------------------------
#DefineFunction GetNumberForm(browser)
    i=0
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.forms
    if( b2 !=0) then
        i=b2.length
    endif
    ObjectClose(BrowserDoc)
    ObjectClose(b2)
    ErrorMode(@CANCEL)
    return i
#EndFunction
;----------------------------------------------------------------------------
; GetFormsName : get all  names of forms
;----------------------------------------------------------------------------
#DefineFunction GetFormsName(browser)
    name=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.forms
    if( b2 !=0) then
        l=b2.length - 1
    	for i=0 to l
    		form=BrowserDoc.forms(%i%)
    		n=form.name
    		if( n != "") then 
    			name=strcat(name,@CRLF,n)
    		else
    			name=strcat(name,@CRLF,"_name%i%")
    		endif
    		ObjectClose(form)
    	next
    endif
    ObjectClose(BrowserDoc)
    ObjectClose(b2)
    ErrorMode(@CANCEL)
    return name
#EndFunction
;----------------------------------------------------------------------------
; GetPluginName : get name plugin number id
;----------------------------------------------------------------------------
#DefineFunction GetPluginName(browser,id)
    ret=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.plugins
    if( b2 !=0) then
        l=b2.length - 1
        if( id <= l) then
    		i1=BrowserDoc.plugins(%id%)
    		ret=i1.name	
    	endif
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return ret  
#EndFunction
;----------------------------------------------------------------------------
; GetPluginFile : get filename plugin number id
;----------------------------------------------------------------------------
#DefineFunction GetPluginFile(browser,id)
    ret=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.plugins
    if( b2 !=0) then
        l=b2.length - 1
        if( id <= l) then
    		i1=BrowserDoc.plugins(%id%)
    		ret=i1.filename	
    	endif
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return ret  
#EndFunction
;----------------------------------------------------------------------------
; GetPluginDescription : get filename plugin number id
;----------------------------------------------------------------------------
#DefineFunction GetPluginDescription(browser,id)
    ret=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.plugins
    if( b2 !=0) then
        l=b2.length - 1
        if( id <= l) then
    		i1=BrowserDoc.plugins(%id%)
    		ret=i1.description	
    	endif
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return ret  
#EndFunction
;----------------------------------------------------------------------------
; GetAllPluginsName : get all  names of plugins
;----------------------------------------------------------------------------
#DefineFunction GetAllPluginsName(browser)
    name_plug=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.plugins
    if( b2 !=0) then
        l=b2.length - 1
    	for i=0 to l
    		plug=BrowserDoc.plugins(%i%)
    		n=plug.name
    		if( n != "") then 
    			name_plug=strcat(name_plug,@CRLF,n)
    		else
    			name_plug=strcat(name_plug,@CRLF,"_name%i%")
    		endif
    		ObjectClose(plug)
    	next
    endif
    ObjectClose(BrowserDoc)
    ObjectClose(b2)
    ErrorMode(@CANCEL)
    return name_plug
#EndFunction
;----------------------------------------------------------------------------
; GetAllImagesName : get all images names 
;----------------------------------------------------------------------------
#DefineFunction GetAllImagesName(browser)
    image=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.images
    if( b2 !=0) then
        l=b2.length - 1
    	for i=0 to l
    		image=BrowserDoc.images(%i%)
    		n=image.name
    		if( n != "") then 
    			image=strcat(image,@CRLF,n)
    		else
    			image=strcat(image,@CRLF,"_name%i%")
    		endif
    	next
    endif
    ObjectClose(BrowserDoc)
    ObjectClose(b2)
    ErrorMode(@CANCEL)
    return image
#EndFunction
;----------------------------------------------------------------------------
; GetNumberImages : get number of images 
;----------------------------------------------------------------------------
#DefineFunction GetNumberImages(browser)
    l=0
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.images
    if( b2 !=0) then
        l=b2.length
    endif
    ObjectClose(BrowserDoc)
    ObjectClose(b2)
    ErrorMode(@CANCEL)
    return l
#EndFunction
;----------------------------------------------------------------------------
; GetImageName : get image name number id
;----------------------------------------------------------------------------
#DefineFunction GetImageName(browser,id)
    ret=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.images
    if( b2 !=0) then
        l=b2.length - 1
        if( id <= l) then
    		i1=BrowserDoc.images(%id%)
    		ret=i1.name	
    	endif
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return ret  
#EndFunction
;----------------------------------------------------------------------------
; GetAllLink : get all  links of html page
;----------------------------------------------------------------------------
#DefineFunction GetAllLink(browser)
    ret=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.links
    if( b2 !=0) then
        l=b2.length - 1
    	for i=0 to l
    		i1=BrowserDoc.links(%i%)
    		j=i1.href
    		if(  j != "") then ret=strcat(ret,@CRLF,j)
    	next
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return ret  
#EndFunction
;----------------------------------------------------------------------------
; GetLink : get  links number id
;----------------------------------------------------------------------------
#DefineFunction GetLink(browser,id)
    ret=""
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.links
    if( b2 !=0) then
        l=b2.length - 1
        if( id <= l) then
    		i1=BrowserDoc.links(%id%)
    		ret1=i1.href
    		ret=ret1	
    	endif
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return ret  
#EndFunction
;----------------------------------------------------------------------------
; GetNumberLink : get  number of links 
;----------------------------------------------------------------------------
#DefineFunction GetNumberLink(browser)
    nb=0
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.links
    ret=""
    if( b2 !=0) then
        nb1=b2.length
        nb=nb1
        if( nb > 0) then nb=nb+1
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return nb  
#EndFunction
;----------------------------------------------------------------------------
; GetNumberPlugins : get  number of plugins 
;----------------------------------------------------------------------------
#DefineFunction GetNumberPlugins(browser)
    nb=0
    ErrorMode(@OFF)
    BrowserDoc = Browser.Document
    b2=BrowserDoc.plugins
    ret=""
    if( b2 !=0) then
        nb1=b2.length
        nb=nb1
        if( nb > 0) then nb=nb+1
    endif
    ObjectClose(b2)
    ObjectClose(BrowserDoc)
    ErrorMode(@CANCEL)
    return nb  
#EndFunction
;----------------------------------------------------------------------------
; OpenUrl : Open html page with ie in visible or hidden mode
;           visible == @TRUE  => visible mode 
;           visible == @FALSE => hidden mode
;----------------------------------------------------------------------------
#DefineFunction OpenUrl(url,visible)
    Browser = ObjectOpen("InternetExplorer.Application")
    if( visible == @OFF || visible == @ON) then
    	browser.visible = visible
    else
    	browser.visible = @TRUE
    endif

    browser.navigate(url)

;-- Wait for it to not be busy
   While 1
	busystate=browser.Busy
	readystate=browser.ReadyState
	if busystate==0 && readystate==4 then break
	TimeDelay(0.5)
   Endwhile
   return browser
#EndFunction
;----------------------------------------------------------------------------
; CloseUrl : close html page
;----------------------------------------------------------------------------
#DefineFunction CloseUrl(browser)
   h = Browser.hwnd
   h=Dec2Hex(h)	 ; convert to hex
   h=StrFixLeft(h,"0",8)
   winid=strcat("#WIN$ID#",h)
   if( ! Winexist(winid) ) then
   	Winclose(winid)
   else
      BrowserDoc = Browser.Document
      title=BrowserDoc.title
      winid=winidGet(title)
      ObjectClose(BrowserDoc)
      Winclose(winid)
   endif
#EndFunction
;----------------------------------------------------------------------------
; AskHtmlFile : choose local html page
; htmlfile = "" if cancel button is pressed
;----------------------------------------------------------------------------
#DefineFunction AskHtmlFile()
   htmlfile=AskFileName("Choose a file",Dirget(),"html file|*.html|htm file|*.htm|","",1)
   return htmlfile
:cancel
   htmlfile=""
   return htmlfile
#EndFunction

;----------------------------------------------------------------------------
;  E X A M P L E 
;----------------------------------------------------------------------------
:main

;winbatch error handler 
IntControl(73, 2, 0, 0, 0)

;open ie in visible mode
htmlfile=""
htmlfile=AskHtmlFile()
if( htmlfile != "") then
	url=strcat("file://",dirget(),htmlfile)
	f=openurl(url,@TRUE)
else
	f=openurl("http://www.gotomypc.com",@TRUE)
	;f=openurl("http://www.windowware.com/",@TRUE)
endif

mess=""
;get domain
domain=GetDomain(f)
mess=strcat(mess,"domain=",domain,@CRLF)
title=GetTitle(f)
mess=strcat(mess,"title=",title,@CRLF)
t=GetLastModified(f)
mess=strcat(mess,"last modified=",t,@CRLF)
color=GetLinkColor(f)
mess=strcat(mess,"link color=",color,@CRLF)
vcolor=GetVlinkColor(f)
mess=strcat(mess,"visited link color=",vcolor,@CRLF)
style=GetStyleSheets(f)
mess=strcat(mess,"style sheet=",style,@CRLF)
url=GetUrl(f)
mess=strcat(mess,"url=",url,@CRLF)
location=GetLocation(f)
mess=strcat(mess,"location=",location,@CRLF)
cookie=GetCookie(f)
mess=strcat(mess,"cookie=",cookie,@CRLF)

message("INFO all link",mess)
;SetLinkColor(f,"#999999")
;SetLinkColor(f,"red")
SetLinkColor(f,0)

;get number of plugins
nbp=GetNumberPlugins(f)
message("INFO plugins",strcat("Number of plugins=",nbp))
if ( nbp > 0) then
	plug_names=GetAllPluginsName(f)
	for i=0 to nbp-1
		name=GetPluginsName(f,i)
		fichier=GetPluginsFile(f,i)
		desc=GetPluginsDescription(f,i)		
	next
endif
;get number of images
nbi=GetNumberImages(f)
message("INFO images",strcat("Number of images=",nbi))
if ( nbi> 0) then
	mess=strcat("Image name(s)",@CRLF)
	inames=GetAllImagesName(f)
	for i=0 to nbi-1
		name=GetImageName(f,i)
		mess=strcat(mess,name,@CRLF)
	next
	message("INFO image(s)",mess)
endif

;get all links in html page
links=GetAllLink(f)
message("INFO all link",links)

;get number of link
; 0 : no link
ilink=GetNumberLink(f)
for i=0 to ilink-1
	; get name of each link
	link=GetLink(f,i)
	;message("INFO link", link)
next
; call one link
if( ilink > 0) then
	i=AskItemList("Choose link",links,@CRLF,@sorted,@single)
	i=StrReplace(i,"http://","")
	i=strcat("http://",i)
	g=openurl(i,@TRUE)
	CloseUrl(g)
endif

;get names of forms
name=GetFormsName(f)
message("INFO form",name)
;get number of forms
nb=GetNumberForm(f)
for i=0 to nb-1
	; get info for each form
	mess=""
	name=GetFormName(f,i)
	mess=strcat(mess,"name=",name,@CRLF)
	
	method=GetFormMethod(f,i)
	mess=strcat(mess,"method=",method,@CRLF)
	
	nb_control=GetFormNumberControl(f,i)
	mess=strcat(mess,"nb_control=",nb_control,@CRLF)
	
	action=GetFormAction(f,i)
	mess=strcat(mess,"action=",action,@CRLF)
	
	target=GetFormTarget(f,i)
	mess=strcat(mess,"target=",target,@CRLF)
	
	message("INFO form",mess)
	; get info for each control
	for j=0 to nb_control-1
		mess=""
		;get info for each control in one form
		name=GetFormControlName(f,i,j)
		mess=strcat(mess,"name=",name,@CRLF)
		
		type=GetFormControlName(f,i,j)
		mess=strcat(mess,"type=",type,@CRLF)
		
		value=GetFormControlValue(f,i,j)
		mess=strcat(mess,"value=",value,@CRLF)
		
		id=GetFormControlID(f,i,j)
		mess=strcat(mess,"id=",id,@CRLF)
		
		;change value for one control
		SetFormControlValue(f,i,j,"toto")
		
		message("INFO form control",mess)
	next
	if( strupper(method) == "POST") then
		;post form
		rep=AskYesNo("SUBMIT","Submit first form")
		if( rep == @YES) then
			FormSubmit(f,i)
		endif
	endif
next
;get html page
html=GetHtml(f)
message("INFO html",html)
;get text in html page
text=GetText(f)
message("INFO texte",text)
;close ie
CloseUrl(f)
exit
:WBERRORHANDLER
Error=LastError()
DebugTrace(@ON,"trace2.txt")
msg=strcat("LastError String is",IntControl(34,Error,0,0,0))
IntControl(73, 2, 0, 0, 0)
return

Article ID:   W15743
File Created: 2003:05:13:11:29:54
Last Updated: 2003:05:13:11:29:54