Why is this frame.onload not triggered?

I have a web page that calls an onload method myonload as a final line in the <script> section of the header:

...
window.onload = myonload;
</script>
</head>

The document has an iframe called MainFrame. Inside myonload, I have a function that checks if this iframe is loaded with

function myonload() {
    frame = document.getElementById("MainFrame")
    frame.onload = function(e) { ... }
    ...
}

Everything works as expected, except that the frame.onload is NOT triggered when I press the browser refresh button. It does work if I refresh the page with Ctrl-R`, though.

Now, if I replace

 window.onload = myonload;

with

 document.addEventListener('DOMContentLoaded', myonload);

the thing seems to work well.

Why is that, and how to handle the refresh properly?