Pseudo-communication between html and ahk

Source: Internet
Author: User

Recently, I helped my friends develop a things. I used ahk as the shell (the full screen untitled top window is easy to implement with ahk). The content is the loaded html (which includes some flash, communication with flash and html), but this is not the focus, the focus is that later html (js/flash) control to disable ahk, this demand is hard for me, I never imagined how to implement it.

Today, I accidentally read the section about activeX in the ahk help document. I found that the example shows how to use ComObjConnect to handle public events of objects. So I came up with a clever method, which is very simple to implement, I am so embarrassed to write an article to introduce this method, but I still want to record it, because it is really useful.

Ahk code:

# NoEnv
# SingleInstance focus

Gui, Add, ActiveX, w700 h400 vWB, Shell. Explorer
WB. Navigate (A_ScriptDir. "\ index.html ")
The focus is on
ComObjConnect (WB, WB_events)

Gui, Show

Return

Class WB_events
{
; Processing method, of course, you can also listen to other events
NavigateComplete2 (wb, url)
{
Simple parsing with SplitPath is very convenient
SplitPath, url, fullCmd, DISCARD, opt, cmd

If (cmd = "test ")
{
Traytip, Test, This is "test" command.
}
Else if (cmd = "_ CLOSE __")
{
ExitApp
}
Else
{
Traytip, % fullCmd %, cmd: % cmd % ', opt: % opt %
}
}
}

GuiEscape:
GuiClose:
Exitapp

Html code:
<Ul>
<Li> <a href = "test" target = "_ cp"> test </a> </li>
<Li> <a href = "command. options" target = "_ cp"> aaa. bbb </a> </li>
<Li> <a href = "_ CLOSE _" target = "_ cp"> close </a> </li>
</Ul>

<Iframe name = "_ cp" src = "about: blank" style = "display: none;"> </iframe>

Brief description: www.2cto.com
Put an iframe in html to receive the "command" and write the "command" to be sent on the link. ahk listens to the NavigateComplete2 event, parse the url in the processing function (the format is defined by myself. I think of a simple rule as command. options, so that the SplitPath method can be easily used to parse all parts and then hand over all the work to ahk ;)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.