I'm having a problem with the window.onload event in JavaScript. I'm trying to execute some code when the page loads, but it doesn't seem to work when I refresh the page.

<script>
window.onload = function() {
// My code here
alert("Page loaded!");
};
</script>

This works fine when I initially load the page, but when I refresh it, the code doesn't run. Can anyone help me figure out why this is happening?