Embed web page in ahk's GUI

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Haswell
Posts: 90
Joined: 21 Feb 2016, 17:11

Embed web page in ahk's GUI

04 Apr 2018, 08:55

How to embed web-page into my ahk-scripts?
I just need to view some web-page inside my GUI.
Where I can find examples?
Focusing our efforts on non-productive and non-creative endeavours wastes lives as surely as war.
Jacque Fresco / The best that money can't buy
garry
Posts: 3775
Joined: 22 Dec 2013, 12:50

Re: Embed web page in ahk's GUI

04 Apr 2018, 09:53

an example

Code: Select all

;EDIT : modified 20180405 , user tank >>  "wb.silent := true"

;-------- saved at Mittwoch, 18. Februar 2015 19:45:55 XP netbook
;-------- https://autohotkey.com/boards/viewtopic.php?f=5&t=6445 -----------
;-- a browser  from user 'Soft' and 'Lexikos'
;===========================================================================

f1=https://autohotkey.com/boards/
filename1=Browser SOFT

Gui,2: Add, Edit, w930 r1 vURL,%f1%
Gui,2: Add, Button, x5 y25  gBrB, <
Gui,2: Add, Button, x+1 y25 gBrF, >
Gui,2: Add, Button, x+6 yp w44 Default gA1, Go
;Gui,2: Add, ActiveX, xm w980 h640 vWB, Shell.Explorer
Gui,2: Add, ActiveX, xm w1080 h720 vWB, Mozilla.Browser
wb.silent := true
ComObjConnect(WB, WB_events)    ;- Connect WB's events to the WB_events class object.
Gui,2: Show,,%filename1%
gosub,a1
return

a1:
Gui,2: Submit, NoHide
try {WB.Navigate(URL)
}catch e{
xxx:=e.Message
msgbox, 262208,ERROR,Error=`n%xxx%`n------------------------------------------`n
return
}
return

Brb:
try{WB.GoBack()
}catch e{
xxx:=e.Message
;msgbox, 262208,ERROR,Error=`n%xxx%`n------------------------------------------`n
return
}
return

BrF:
try{WB.GoForward()
}catch e{
xxx:=e.Message
;msgbox, 262208,ERROR,Error=`n%xxx%`n------------------------------------------`n
return
}
return

class WB_events
{
NavigateComplete2(wb, NewURL)
  {
  GuiControl,2:, URL, %NewURL%  ;- Update the URL edit control.
  }
}

2GuiClose:
ExitApp
Last edited by garry on 05 Apr 2018, 09:44, edited 1 time in total.
Haswell
Posts: 90
Joined: 21 Feb 2016, 17:11

Re: Embed web page in ahk's GUI

04 Apr 2018, 15:40

Thank you garry for a nice example.
The only issue is every web-page navigation gives an error in JavaScript:
1786.png
1786.png (140.41 KiB) Viewed 4338 times
Do you know how to fix it?
Focusing our efforts on non-productive and non-creative endeavours wastes lives as surely as war.
Jacque Fresco / The best that money can't buy
garry
Posts: 3775
Joined: 22 Dec 2013, 12:50

Re: Embed web page in ahk's GUI

05 Apr 2018, 00:58

don't know, try search for other example or someone can help
I have the same problem if I use windows internet explorer , with firefox is OK
for me :

Code: Select all

internet explorer > Shell.Explorer     =  failure
firefox                > Mozilla.Browser  =  OK
garry
Posts: 3775
Joined: 22 Dec 2013, 12:50

Re: Embed web page in ahk's GUI

05 Apr 2018, 01:21

found another example , user 'jethrow'
https://autohotkey.com/board/topic/5698 ... ntry362159

Code: Select all

;-------- saved at Freitag, 27. Februar 2015 20:23:37 --------------
;-------- https://autohotkey.com/board/topic/56987-com-object-reference-autohotkey-v11/page-2#entry362159
;// open Standard Internet Explorer
;xxx=Shell.Explorer     ;- Microsoft windows browser
xxx:="InternetExplorer.Application"
;xxx:="Mozilla.Browser"    ;- mozilla firefox browser NOK
;xxx:="MozillaExplorer.Application"


wb := ComObjCreate(xxx) ;// create IE
wb.Visible := true ;// show IE
wb.GoHome() ;// Navigate Home

;// the ReadyState will be 4 when the page is loaded
while wb.ReadyState <> 4
    continue

;// get the Name & URL of the site
msgbox, 262208, , % "Name: " wb.LocationName
    . "`nURL: " wb.LocationURL
    . "`n`nLet's Navigate to Autohotkey.com..." ,6

;// get the Document - which is the webpage
document := wb.document

;// Navigate to AutoHotkey.com
wb.Navigate("www.AutoHotkey.com") ;// 2nd param - see NavConstants

;// the Busy property will be true while the page is loading
while wb.Busy
    continue
msgbox, 262208, ,Page Loaded...Going Back Now , 8

;// Go Back
wb.GoBack()

while wb.Busy
    continue
msgbox, 262208, ,The page is loaded - now we will refresh it... ,8


;// Refresh the page
wb.Refresh()
while wb.Busy
    continue
msgbox, 262208, ,Now that the page is Refreshed `, we will Select All (^a)... ,8

;// Execute Commands with ExecWB()
SelectAll := 17 ;// see CMD IDs
wb.ExecWB(SelectAll,0) ;// second param as "0" uses default options

Sleep 2000
msgbox, 262208, ,Now that we are done`, we will exit Internet Explorer ,6

;// Quit Internet Explorer
wb.Quit()
gregster
Posts: 9064
Joined: 30 Sep 2013, 06:48

Re: Embed web page in ahk's GUI

05 Apr 2018, 01:31

Code: Select all

;xxx:="Mozilla.Browser"    ;- mozilla firefox browser NOK
;xxx:="MozillaExplorer.Application"

wb := ComObjCreate(xxx)	;// create IE
It would be news to me that there is a possibility to connect to Firefox via COM. I have never heard about anything like that. IE, sure...

That's probably also the reason why Haswell gets the error message about the not supported method 'getElementsbyClassname'. That doesn't really work for you with mozilla, Gary?
garry
Posts: 3775
Joined: 22 Dec 2013, 12:50

Re: Embed web page in ahk's GUI

05 Apr 2018, 01:57

@gregster
it was my bad experiments , it works only with 'InternetExplorer.Application'
this works as 'jethrow' wrote :

Code: Select all

xxx:="InternetExplorer.Application"
wb := ComObjCreate(xxx)   ;// create IE
first example above works for me with mozilla.browser ( ActiveX )

Code: Select all

;Gui,2: Add, ActiveX, xm w980 h640 vWB, Shell.Explorer   ;- failure
Gui,2: Add, ActiveX, xm w1080 h720 vWB, Mozilla.Browser ;- good
ComObjConnect(WB, WB_events)    ;- Connect WB's events to the WB_events class object.
Last edited by garry on 05 Apr 2018, 07:34, edited 1 time in total.
gregster
Posts: 9064
Joined: 30 Sep 2013, 06:48

Re: Embed web page in ahk's GUI

05 Apr 2018, 02:10

I still doubt that an ActiveX element can load anything else than something based on the Internet Explorer. I think you are not really loading mozilla with this line above, but still some kind of (functionally watered-down) IE-browser element. That is what ActiveX was made for, while Mozilla has no COM interface to connect to... :think:
garry
Posts: 3775
Joined: 22 Dec 2013, 12:50

Re: Embed web page in ahk's GUI

05 Apr 2018, 05:23

thank you gregster, I don't know what really happens, but first script works with 'Mozilla.Browser' without failure
Haswell
Posts: 90
Joined: 21 Feb 2016, 17:11

Re: Embed web page in ahk's GUI

05 Apr 2018, 06:33

But for me all ones give this error.
Focusing our efforts on non-productive and non-creative endeavours wastes lives as surely as war.
Jacque Fresco / The best that money can't buy
User avatar
tank
Posts: 3128
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Embed web page in ahk's GUI

05 Apr 2018, 08:37

For any object type that is invalid, Shell.Application is loaded. It appears to work but isnt actually using mozilla
What you are missing is WB.Silent := true
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
User avatar
tank
Posts: 3128
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Embed web page in ahk's GUI

05 Apr 2018, 08:55

Sorry meant Shell.Explorer
any way here is a working script

Code: Select all

;-------- saved at Mittwoch, 18. Februar 2015 19:45:55 XP netbook
;-------- https://autohotkey.com/boards/viewtopic.php?f=5&t=6445 -----------
;-- a browser  from user 'Soft' and 'Lexikos'
;===========================================================================

f1=https://autohotkey.com/boards/
filename1=Browser SOFT

Gui Add, Edit, w930 r1 vURL,%f1%
Gui Add, Button, x5 y25  gBrB, <
Gui Add, Button, x+1 y25 gBrF, >
Gui Add, Button, x+6 yp w44 Default gA1, Go
;Gui Add, ActiveX, xm w980 h640 vWB, Shell.Explorer
;~ Gui Add, ActiveX, xm w1080 h720 vWB, Mozilla.Browser
Gui Add, ActiveX, xm w1080 h720 vWB, Shell.Explorer
;~ ComObjConnect(WB, WB_events)    ;- Connect WB's events to the WB_events class object.
Gui Show,,%filename1%
Gui Submit, NoHide
wb.silent := true
gosub,a1
return

a1:
Gui Submit, NoHide
WB.Navigate(URL)
return

Brb:
try{WB.GoBack()
}catch e{
xxx:=e.Message
msgbox, 262208,ERROR,Error=`n%xxx%`n------------------------------------------`n
return
}
return

BrF:
try{WB.GoForward()
}catch e{
xxx:=e.Message
msgbox, 262208,ERROR,Error=`n%xxx%`n------------------------------------------`n
return
}
return

class WB_events
{
NavigateComplete2(wb, NewURL)
  {
  GuiControl, Text, URL, %NewURL%  ;- Update the URL edit control.
  }
}

GuiClose:
ExitApp
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
garry
Posts: 3775
Joined: 22 Dec 2013, 12:50

Re: Embed web page in ahk's GUI

05 Apr 2018, 09:39

@tank
What you are missing is WB.Silent := true
thank you tank , works fine now with both , without failure
for me it looks better when I use Mozilla.Browser ( have Firefox as default browser )

Code: Select all

;Gui,2: Add, ActiveX, xm w980 h640 vWB, Shell.Explorer      ; OK
Gui,2: Add, ActiveX, xm w1080 h720 vWB, Mozilla.Browser   ; OK
wb.silent := true
ComObjConnect(WB, WB_events)    ;- Connect WB's events to the WB_events class object / should activate this to update the URL edit control ( ? )
EDIT :
in my first script above
when I go Forward > it updates the URL in edit control
when I go Backward > Edit control is empty ( doesn't show the previous URL )
Haswell
Posts: 90
Joined: 21 Feb 2016, 17:11

Re: Embed web page in ahk's GUI

05 Apr 2018, 12:22

Oh yes!
It works now.
Focusing our efforts on non-productive and non-creative endeavours wastes lives as surely as war.
Jacque Fresco / The best that money can't buy

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: sanmaodo and 149 guests