We usually place JavaScript <script>
tags at the bottom of the HTML document immediately before the closing </body>
with the advantage that they are executed after all the elements are already available in the DOM and a few more things .
However, I am using a frame 1 document that has a <frameset>
instead of a <body>
. I do not want to put them in the <head>
document, because they will not have direct access to DOM elements below 3 . And I don't want to use an <iframe>
in a standard body tag of either 4 . I tried
<head> <title>Framesets are interesting</title> </head> <frameset cols="50%,50%"> <frame id="frame-a" src="a.html"> <frame id="frame-b" src="b.html"> <script type="text/javascript"> console.log("hello world!"); console.log(document.getElementById("frame-a")); </script> </frameset>
However, the script was not executed at all, it did not even appear in the DOM inspector. Undoubtedly, a <frameset>
can only contain <frame>
and <noframes>
tags. But there is no way to get scripts to execute after the <frame>
?
Just for reference, placing them after </frameset>
as is sometimes done using <body>
s , also does not work.
1: Yes, I know that they are out of date. It was just natural choice 2 for my project, a neat side by side that shows two documents and scrolls them together in a complicated way.
2: ... and I have never used them before, so I wanted to try it. 3: This is what I ended up with, because the onload handler is trivial. Nevertheless, the question remains, I am curious.
4: works fine, but requires complex CSS styling
source share