+ 1

"OnLoad" executed before page loaded? [External Link]

I was working with iFrames and wrote some code making sure that the frame resize as soon as the page is loaded, but I came across an interesting bug. 3 of my pages works perfectly fine when viewed, but upon returning to the home page, it doesn't resize when it's loaded. I set up an alert to tell me when the page is successfully loaded, and see that the alert comes before the /home.html is loaded. I assume that the home.html's data is loading fast and javascript throws the alert before the page is actually loaded. Here's my website I'm working on: https://preview.c9users.io/zalimitless/guesthouse/index.htm To see the bug click on any other page, then click on home again. Can someone tell me how I can get around this bug? Javascript code: https://code.sololearn.com/WYRJH3x5y1dC (Please don't judge, the page is still under construction)

18th Apr 2018, 9:38 PM
Limitless
Limitless - avatar
2 Respuestas
+ 1
Hi Limitless I think the Window or Document on load is firing before the body is completed in the case of your home page. try something like this window.onload = function(){ window.document.body.onload = myFunc} I also assume you have done usual trick of putting the script link at the bottom of the HTML rather than the head.
18th Apr 2018, 10:53 PM
Mike Choy
Mike Choy - avatar
+ 1
Yes Mike, the script was added at the bottom of the page. The onload function triggers a function that gets the height of the content inside the iframe after it's supposed to load: <iframe id="Flex-Frame" onload="AdjustIframeHeightOnLoad()"></iframe> If I insert it inside the content's code it won't able to change the iFrame's properties
18th Apr 2018, 11:52 PM
Limitless
Limitless - avatar