Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (20.3k points)

I'm executing an external script, using a <script> inside <head>.

Now since the script executes before the page has loaded, I can't access the <body>, among other things. I'd like to execute some JavaScript after the document has been "loaded" (HTML fully downloaded and in-RAM). Are there any events that I can hook onto when my script executes, that will get triggered on page load?

1 Answer

0 votes
by (40.7k points)

The below solution will work:

<body onload="script();">

or

document.onload = function ...

or else

window.onload = function ...

Note: The last option is a better way to go since it is considered more standard.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...