1

Using AhtuHotkey 2.0 Beta1 (i assume VBA script as well) getElementsByTagName() only shows opening tag for HTML5 tags section and nav however works with all other HTML4 tags.

AutoHotkey Code

HTMLObj := ComObject("HTMLfile")
HTMLObj.write(HTML)

DOMObj := HTMLFileObj.getElementsByTagName("section") 

msgbox DOMObj[0].outerHTML

following will return just opening tag <section class=mysection> i think it simply does not know how to handle HTML5 tags. Is there solution, i am on Windows 7 x64 Service Pack 1

LilBro
  • 81
  • 5
  • You know, you could give some feedback to my answer. Does it work? Does it not work? Any errors? Any comments at all? Setting up a bounty and then abandoning the question is kind of strange. – Tomalak Oct 03 '21 at 09:51
  • Pardon, i got locked out of this account. Thanks for help perhaps you ask admin to mark it as solution. – Roman Toasov Oct 23 '21 at 13:24

1 Answers1

0

Old versions of IE('s HTML parser) treat unknown elements as inline elements by default. That means the parser auto-closes them as soon the next known block element is encountered.

Try this (a bare-bones version of the much more comprehensive https://github.com/aFarkas/html5shiv):

html5shim =
(
<script>
  document.createElement('header');
  document.createElement('section');
  document.createElement('main');
  document.createElement('article');
  document.createElement('aside');
  document.createElement('nav');
  document.createElement('footer');
</script>
)

HTMLObj := ComObject("HTMLfile")
HTMLObj.write(html5shim)
HTMLObj.write(HTML)

DOMObj := HTMLFileObj.getElementsByTagName("section") 

msgbox DOMObj[0].outerHTML

An alternative way would be to add CSS that declares these elements as block elements:

<style type="text/css">
  header, section, main, article, aside, nav, footer { display: block; }
</script>
Tomalak
  • 332,285
  • 67
  • 532
  • 628