The instanceof window.HTMLElement statement returns false when inside an iframe element in very specific situations, this causes the script to stop working thus rendering a blank table of contents.
Solution
I've added instanceof window.parent.HTMLElement to check if an element was created by the parent document. This check only works in iframes in the same domain, so I wrapped it in a try-catch block to prevent errors.
Problem
The
instanceof window.HTMLElement
statement returnsfalse
when inside an iframe element in very specific situations, this causes the script to stop working thus rendering a blank table of contents.Solution
I've added
instanceof window.parent.HTMLElement
to check if an element was created by the parent document. This check only works in iframes in the same domain, so I wrapped it in a try-catch block to prevent errors.