jeeswg's Internet Explorer and HTML tutorial

Helpful script writing tricks and HowTo's
User avatar
jeeswg
Posts: 5442
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: LATCH ONTO ACTIVE TAB, GET WEBPAGE TITLE AND URL, CLOSE TAB

Code: Select all

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

COM OBJECT: FUNCTIONS FOR LISTING / COUNTING / FOCUSING TABS

Internet Explorer: activate tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 27#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 ... 70#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 ... 85#p201485

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

COM OBJECT: TABLES: 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 ... 84#p202084
Extract table element from a page - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 80#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/8919 ... nd-tofile/
UrlDownloadToFile - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/9764 ... oadtofile/

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

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 ... 34#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

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/9764 ... oadtofile/

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

MOZILLA FIREFOX / GOOGLE CHROME / OTHER WEB BROWSERS

Firefox/Chrome, get tab names/focus tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?t=26947
[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/3213 ... -atlaxwin/

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

COM OBJECT (GENERAL)

Basic Webpage Controls with JavaScript / COM - Tutorial - Tutorials - AutoHotkey Community
https://autohotkey.com/board/topic/4705 ... -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 ... 70#p201470
start chm file with specific page - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/1298 ... ific-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 ... 55#p191155

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

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/353 ... ication-vs

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

LINKS (SOME EXAMPLES):
javascript - Can I put logical operators in document.querySelectorAll? If so, how? - Stack Overflow
https://stackoverflow.com/questions/365 ... -if-so-how
javascript - querySelectorAll with multiple conditions - Stack Overflow
https://stackoverflow.com/questions/340 ... conditions
javascript - How to use querySelectorAll only for elements that have a specific attribute set? - Stack Overflow
https://stackoverflow.com/questions/107 ... ribute-set
Last edited by jeeswg on 06 Dec 2018, 17:34, edited 1 time in total.
malcev
Posts: 112
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
}

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 7 guests