I've recently been developing some macros that have similarities with what you are asking for, so here is my take based on the approach I've been exploring:
Close HTML prompt with cmd+w CALLING.kmmacros (1.9 KB)
Close HTML prompt with cmd+w SUBMACRO.kmmacros (4.8 KB)