jeeswg's Internet Explorer and HTML tutorial

Helpful script writing tricks and HowTo's
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

jeeswg's Internet Explorer and HTML tutorial

14 May 2017, 21:36

==================================================

COM OBJECT: WBGET FUNCTION

- WBGet function, used in many of the scripts below.
- It can be used to latch onto an Internet Explorer_Server control in Internet Explorer/HTML Help/elsewhere, and do things like get/set the url and zoom etc.

WBGet function - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=39869

==================================================

COM OBJECT: OPEN A URL

Code: Select all

q:: ;internet explorer - set url of current tab
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
vUrl := "https://autohotkey.com/docs/AutoHotkey.htm"
oWB.Navigate(vUrl)
oWB := ""
return

w:: ;internet explorer - open url in existing window
vUrl := "https://autohotkey.com/docs/AutoHotkey.htm"
;if Internet Explorer is the default browser:
;Run, % vUrl
;otherwise:
Run, cmd.exe /c start "C:\Program Files\Internet Explorer\iexplore.exe" "%vUrl%",, Hide
return

;w:: ;internet explorer - open url in existing window (alternative)
vUrl := "https://autohotkey.com/docs/AutoHotkey.htm"
oShell := ComObjCreate("Shell.Application")
oShell.Open(vUrl)
oShell := ""
return

e:: ;internet explorer - open url in new window
vUrl := "https://autohotkey.com/docs/AutoHotkey.htm"
;Run, "C:\Program Files\Internet Explorer\iexplore.exe" "%vUrl%"
Run, iexplore.exe "%vUrl%"
return
==================================================

COM OBJECT: GET WEBPAGE TITLES AND URLS

Latch onto active tab, get webpage title and url (and close tab):

Code: Select all

;WBGet function - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=39869

q:: ;internet explorer - latch onto active tab, get webpage title and url
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
MsgBox, % oWB.document.title "`r`n" oWB.document.url
;oWB.Quit() ;close tab
;oWB.Quit ;close tab (also works)
oWB := ""
return
Get webpage titles and urls for most recently active Internet Explorer window:

Code: Select all

q:: ;internet explorer - get webpage titles and urls for most recently active IE window
;DetectHiddenWindows, On
WinGet, hWnd, ID, ahk_class IEFrame
if !hWnd
	return
vOutput := ""
for oWB in ComObjCreate("Shell.Application").Windows
{
	if (oWB.HWND = hWnd)
	{
		try vUrl := oWB.document.url
		catch
			vUrl := ""
		try vTitle := oWB.document.title
		catch
			vTitle := ""
		vOutput .= vTitle "`r`n" vUrl "`r`n`r`n"
	}
}
oWB := ""
vOutput := SubStr(vOutput, 1, -2)
;Clipboard := vOutput
MsgBox, % vOutput
return
Get webpage titles and urls for all existing tabs:

Code: Select all

q:: ;internet explorer - get webpage titles and urls for all existing tabs
DetectHiddenWindows, On
vOutput := ""
for oWB in ComObjCreate("Shell.Application").Windows
{
	if (oWB.Name = "Internet Explorer")
	{
		try vUrl := oWB.document.url
		catch
			vUrl := ""
		try vTitle := oWB.document.title
		catch
			vTitle := ""
		vOutput .= vTitle "`r`n" vUrl "`r`n`r`n"
	}
}
oWB := ""
vOutput := SubStr(vOutput, 1, -2)
;Clipboard := vOutput
MsgBox, % vOutput
return
==================================================

COM OBJECT: FUNCTIONS FOR LISTING / COUNTING / FOCUSING TABS

Internet Explorer: activate tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=34222&p=173827#p173827

==================================================

COM OBJECT: ZOOM / TEXT SIZE (EXECWB)

Internet Explorer get/set zoom/text size - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=26359

==================================================

MENU ITEMS

[save as]
Windows 7 - invert selection, set details view/list view (trigger Explorer/Internet Explorer menu items) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=27564

[hide/show toolbars]
Internet Explorer Winset command list - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=28759

How to open the context menu of the window's title bar - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=35975&p=165570#p165570

Code: Select all

;PostMessage, 0x80F0, 0xA5D7,,, A ;WM_APP+240 := 0x80F0 ;Show tabs on a separate row

;New window: duplicate current tab as a new tab in a new window
;New session: open home page as a new tab in a new window

;PostMessage, 0x111, 381,, Shell DocObject View1, A ;WM_COMMAND := 0x111 ;New tab
;PostMessage, 0x111, 384,, Shell DocObject View1, A ;WM_COMMAND := 0x111 ;Duplicate tab
;PostMessage, 0x111, 275,, Shell DocObject View1, A ;WM_COMMAND := 0x111 ;New window
;PostMessage, 0x111, 285,, Shell DocObject View1, A ;WM_COMMAND := 0x111 ;New session
;PostMessage, 0x111, 256,, Shell DocObject View1, A ;WM_COMMAND := 0x111 ;Open...
;PostMessage, 0x111, 258,, Shell DocObject View1, A ;WM_COMMAND := 0x111 ;Save as...
;PostMessage, 0x111, 382,, Shell DocObject View1, A ;WM_COMMAND := 0x111 ;Close tab
;PostMessage, 0x111, 259,, Shell DocObject View1, A ;WM_COMMAND := 0x111 ;Page setup...
;PostMessage, 0x111, 260,, Shell DocObject View1, A ;WM_COMMAND := 0x111 ;Print...
;PostMessage, 0x111, 277,, Shell DocObject View1, A ;WM_COMMAND := 0x111 ;Print preview...
;PostMessage, 0x111, 262,, Shell DocObject View1, A ;WM_COMMAND := 0x111 ;Properties
==================================================

COM OBJECT: GET REDIRECTED URL

get redirected url (handle file links and focus loss) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=30778

==================================================

COM OBJECT: WINDOW SPY

[download iWB2 Learner]
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

Internet Explorer get element under cursor (show borders, show text) (any zoom percentage) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=29458

Internet Explorer Element Spy (alternative to iWB2 Learner) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=13031

==================================================

COM OBJECT: TABS

Internet Explorer: activate tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=34222

Internet Explorer - move tab to new window - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=26117

Firefox/Chrome, get tab names/focus tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26947

==================================================

COM OBJECT: FRAGMENT IDENTIFIERS

list fragment identifiers on a webpage (hash that jumps to point) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=28053

==================================================

COM OBJECT: CREATE UNIQUE IDENTIFIERS FOR TABS

Internet Explorer: get WB hWnds via object loop (+ do win objects have unique object IDs) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=26082

==================================================

COM OBJECT: CARET BROWSING

Internet Explorer: check if caret is visible (IHTMLCaret IsVisible) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=39615

==================================================

COM OBJECT: GET ELEMENT PROPERTY

[getAttribute method]
[try to get html element properties without causing an error message]
Getting href data, why is it so hard? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=40267

==================================================

COM OBJECT: NAVIGATE TO PREVIOUS/NEXT ITEM (ALT+LEFT/ALT+RIGHT)

Suggestions on documentation improvements - Page 18 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=13&t=1434&p=201485#p201485

==================================================

COM OBJECT: GET SELECTED TEXT

Code: Select all

;WBGet function - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=39869

q:: ;internet explorer - get selected text
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
vText := oWB.document.selection.createRange().text
MsgBox, % vText
oWB := ""
return
==================================================

COM OBJECT: TABLES: GET TEXT FROM CELLS

webpages: get table text - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=39131
[Google spreadsheet]
Get spreadsheet info - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=44517&p=202084#p202084
Extract table element from a page - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=43003&p=203780#p203780

==================================================

DOWNLOAD TO FILE/VARIABLE (NOT INTERNET EXPLORER SPECIFIC)

[UrlDownloadToFile via DllCall]
Simple Download (Bin, ToString und ToFile) - Gebrauchsfertige Skripte & Funktionen - AutoHotkey Community
https://autohotkey.com/board/topic/89198-simple-download-bin-tostring-und-tofile/
UrlDownloadToFile - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/97642-urldownloadtofile/

==================================================

CLIPBOARD (NOT INTERNET EXPLORER SPECIFIC)

[add in: html from clipboard]

[put html onto clipboard]
GUI COMMANDS: COMPLETE RETHINK - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=25893&p=170834#p170834

==================================================

HTMLFILE OBJECT

list of every command/function/variable from across all versions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=27321
text/list/table functions (latest: add indentation, get nth(-to-last) line of specified length, html to/from text) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=27023
Using IE.Document.GetElementsByClassname - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=28791

==================================================

WINHTTPREQUEST OBJECT

[note: a WinHttpRequest does not require the use of Internet Explorer]

download urls to vars, partially/fullly, via WinHttpRequest - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=26528
UrlDownloadToFile - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/97642-urldownloadtofile/
urls: get date modified - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=37145

==================================================

MOZILLA FIREFOX / GOOGLE CHROME / OTHER WEB BROWSERS

Firefox/Chrome, get tab names/focus tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26947
Firefox/Chrome: copy titles/urls to the clipboard - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=22&t=66246

[Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium! - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=42890
Using Selenium with AutoHotkey- Cross browser automation! - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=32323
Get the URL of the current (active) browser tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=3702

==================================================

GRAPHICAL USER INTERFACES: ADD INTERNET EXPLORER_SERVER CONTROLS

[create an Internet Explorer_Server control]
[this is now doable via the Gui command and the ActiveX control]
IE_Add() or COM_AtlAxCreateContainer() or AtlAxWin() - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/32138-ie-add-or-com-atlaxcreatecontainer-or-atlaxwin/

==================================================

COM OBJECT (GENERAL)

Basic Webpage Controls with JavaScript / COM - Tutorial - Tutorials - AutoHotkey Community
https://autohotkey.com/board/topic/47052-basic-webpage-controls-with-javascript-com-tutorial/

==================================================

HTML HELP (AUTOHOTKEY HELP) (CHM FILES)

AutoHotkey help file, caret browsing - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=26116
[Solved] AutoHotkey help file navigation - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=30533
HTML Help alternative via Internet Explorer - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=42129
[AutoHotkey Help: focus Index tab]
SendMessage for the new help file of AutoHotkey - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=43262

HTML HELP (API)

DLLCall: Call a topic on existing help window (CHM) with hhctrl.ocx\HtmlHelpA - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=44462&p=201470#p201470
start chm file with specific page - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/12989-start-chm-file-with-specific-page/
[HTML Help: search keyword]
F1 help not jumping to particular URL with v1.1.27.00 help file - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=42014&p=191155#p191155

==================================================

JAVASCRIPT EXAMPLES

Internet Explorer: JavaScript examples - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=60377

==================================================

QUERYSELECTOR / QUERYSELECTORALL

LINKS (BEST):
CSS Selectors Reference
https://www.w3schools.com/cssref/css_selectors.asp
css3 - CSS Selector Clarification: |= vs ^= - Stack Overflow
https://stackoverflow.com/questions/35370441/css-selector-clarification-vs

LINKS (FURTHER):
HTML DOM querySelector() Method
https://www.w3schools.com/jsref/met_document_queryselector.asp
Document.querySelector() - Web APIs | MDN
https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector

LINKS (SOME EXAMPLES):
querySelector/querySelectorAll examples - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=62113
javascript - Can I put logical operators in document.querySelectorAll? If so, how? - Stack Overflow
https://stackoverflow.com/questions/36544941/can-i-put-logical-operators-in-document-queryselectorall-if-so-how
javascript - querySelectorAll with multiple conditions - Stack Overflow
https://stackoverflow.com/questions/34001917/queryselectorall-with-multiple-conditions
javascript - How to use querySelectorAll only for elements that have a specific attribute set? - Stack Overflow
https://stackoverflow.com/questions/10777684/how-to-use-queryselectorall-only-for-elements-that-have-a-specific-attribute-set

==================================================

TEMPORARY INTERNET FILES

Code: Select all

q:: ;Internet Explorer - list Temporary Internet Files
vDir1 := "C:\Users\" A_UserName "\AppData\Local\Microsoft\Windows\Temporary Internet Files"
vOutput := ""
Loop, Files, % vDir1 "\*", FR
{
	vPath := A_LoopFileFullPath
	SplitPath, vPath, vName, vDir, vExt, vNameNoExt, vDrive
	vOutput .= vPath "`r`n"
}
Clipboard := vOutput
MsgBox, % "done"
return
==================================================
Last edited by jeeswg on 13 Jul 2019, 11:09, edited 11 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
malcev
Posts: 1442
Joined: 12 Aug 2014, 12:37

Re: jeeswg's Internet Explorer and HTML tutorial

01 Nov 2018, 09:06

Example of uploading file without running other script to interact with upload form, by teadrinker:

Code: Select all

oIE := ComObjCreate("InternetExplorer.Application")
OnExit( Func("IeQuit").Bind(oIE) )
oIE.visible := true
oIE.navigate("https://www.youtube.com/upload")
While oIE.readyState != 4 || oIE.document.readyState != "complete" || oIE.busy
   Sleep, 10

UnFreeze(200, Func("MyFunc"))
oIE.document.querySelector("input[type=""file""]").click()

MyFunc()  {
   Loop  {
      if WinExist("ahk_class #32770 ahk_exe IEXPLORE.EXE")  {
         MsgBox, do stuff here
         break
      }
      Sleep, 100
   }
}

IeQuit(oIE)  {
   if WinExist("ahk_class #32770 ahk_exe IEXPLORE.EXE")
      ControlClick, Button2
   try oIE.Quit()
}

UnFreeze(timeOut, userFunc)  {
   static SYNCHRONIZE := 0x100000, hGui, oInfo := {}
        , _ := OnMessage( msg := DllCall("RegisterWindowMessage", Str, "WM_INFO"), Func("WM_INFO").Bind(oInfo) )
   if !hGui
      Gui, New, +hwndhGui
   hProc := DllCall("OpenProcess", UInt, SYNCHRONIZE, UInt, 0, UInt, DllCall("GetCurrentProcessId"), Ptr)
   pPtr := GetProcAddr(hProc, hGui, msg, timeOut)
   oInfo.func := userFunc, oInfo.hProc := hProc
   DllCall("CreateThread", Ptr, 0, Ptr, 0, Ptr, pPtr, Ptr, 0, UInt, 0, Ptr, 0)
}

WM_INFO(oInfo)
{
   DllCall("CloseHandle", Ptr, oInfo.hProc)
   oInfo.func.Call()
}

GetProcAddr(Handle, hWnd, Msg, Timeout=-1)
{  ; на основе http://forum.script-coding.com/viewtopic.php?pid=56073#p56073
   static MEM_COMMIT := 0x1000, PAGE_EXECUTE_READWRITE := 0x40
   ptr := DllCall("VirtualAlloc", Ptr, 0, Ptr, A_PtrSize = 4 ? 49 : 85, UInt, MEM_COMMIT, UInt, PAGE_EXECUTE_READWRITE, Ptr)
   , hModule := DllCall("GetModuleHandle", Str, "kernel32.dll", Ptr)
   , pWaitForSingleObject := DllCall("GetProcAddress", Ptr, hModule, AStr, "WaitForSingleObject", Ptr)
   , hModule := DllCall("GetModuleHandle", Str, "user32.dll", Ptr)
   , pSendMessageW := DllCall("GetProcAddress", Ptr, hModule, AStr, "SendMessageW", Ptr)
   , NumPut(pWaitForSingleObject, ptr*1)
   , NumPut(pSendMessageW, ptr + A_PtrSize)
   if (A_PtrSize = 4)  {
      NumPut(0x68, ptr + 8, "UChar")
      , NumPut(Timeout, ptr + 9, "UInt"), NumPut(0x68, ptr + 13, "UChar")
      , NumPut(Handle, ptr + 14), NumPut(0x15FF, ptr + 18, "UShort")
      , NumPut(ptr, ptr + 20), NumPut(0x6850, ptr + 24, "UShort")
      , NumPut(Handle, ptr + 26), NumPut(0x68, ptr + 30, "UChar")
      , NumPut(Msg, ptr + 31, "UInt"), NumPut(0x68, ptr + 35, "UChar")
      , NumPut(hWnd, ptr + 36), NumPut(0x15FF, ptr + 40, "UShort")
      , NumPut(ptr+4, ptr + 42), NumPut(0xC2, ptr + 46, "UChar"), NumPut(4, ptr + 47, "UShort")
   }
   else  {
      NumPut(0x53, ptr + 16, "UChar")
      , NumPut(0x20EC8348, ptr + 17, "UInt"), NumPut(0xBACB8948, ptr + 21, "UInt")
      , NumPut(Timeout, ptr + 25, "UInt"), NumPut(0xB948, ptr + 29, "UShort")
      , NumPut(Handle, ptr + 31), NumPut(0x15FF, ptr + 39, "UShort")
      , NumPut(-45, ptr + 41, "UInt"), NumPut(0xB849, ptr + 45, "UShort")
      , NumPut(Handle, ptr + 47), NumPut(0xBA, ptr + 55, "UChar")
      , NumPut(Msg, ptr + 56, "UInt"), NumPut(0xB948, ptr + 60, "UShort")
      , NumPut(hWnd, ptr + 62), NumPut(0xC18941, ptr + 70, "UInt")
      , NumPut(0x15FF, ptr + 73, "UShort"), NumPut(-71, ptr + 75, "UInt")
      , NumPut(0x20C48348, ptr + 79, "UInt"), NumPut(0xC35B, ptr + 83, "UShort")
   }
   return ptr + A_PtrSize*2
}
Janusz
Posts: 81
Joined: 18 Dec 2020, 17:47

Re: jeeswg's Internet Explorer and HTML tutorial

05 Apr 2021, 06:37

Dear specialists,
Please, does somebody of us know, how to close WEB page, which have been loaded by using

Code: Select all

wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := False
wb.silent := true
P:="www.google.com"
wb.Navigate(P)
How to terminate Iexplore.exe with loaded google.com or other pages. So process will correctly terminate even if loaded Web page would play live stream for example? Unfortunately, simply releasing object do not functioning at all. Iexplore.exe is still active in RAM and WEB page also.
Is it possible to use some command, which will close WEB page? Document close do not work for Me, I AM getting error. I do not want to terminate process by using APi functions, I would be rather to correctly release object so process will really be unloaded from RAM correctly.
Thank you for any help please.
gregster
Posts: 7779
Joined: 30 Sep 2013, 06:48

Re: jeeswg's Internet Explorer and HTML tutorial

05 Apr 2021, 06:46

Janusz wrote:
05 Apr 2021, 06:37
Is it possible to use some command, which will close WEB page?

Code: Select all

wb.quit()
should do.
Janusz
Posts: 81
Joined: 18 Dec 2020, 17:47

Re: jeeswg's Internet Explorer and HTML tutorial

05 Apr 2021, 08:00

I Am very very sorry that I have intruded you. Fortunately, Powerful Microsoft company have developed simple sub Quit so it is safely possible to Quit even Internet Explorer server which has hydden window. IIt is A very good practice to always use object browser build in to Office products to get all possible subs and functions.
User avatar
submeg
Posts: 291
Joined: 14 Apr 2017, 20:39
GitHub: submeg

Re: jeeswg's Internet Explorer and HTML tutorial

16 Jun 2021, 07:01

Now that IE is on the way out, is there the same functionality with Edge?
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:
gregster
Posts: 7779
Joined: 30 Sep 2013, 06:48

Re: jeeswg's Internet Explorer and HTML tutorial

16 Jun 2021, 08:09

Edge has already an IE mode for legacy applications, afaik. If that will eventually support COM, I don't know.
But since Edge is Chromium-based now, it is compatible to the chrome debug protocol and can at least be automated via the Chrome.ahk library. It's not the same, but it can probably replace most usages of the IE COM interface.

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 4 guests