Is there any event handler before onLoad/onPageShow? The trouble with onLoad is if there is any change in display, the page will show up without change until it is fully loaded, then the script will run. What is the best way to make sure it will run as soon as possible?
You can run javascript code at any time. AFAIK it is executed at the moment the browser reaches the <script> tag where it is in. But you cannot access elements that are not loaded yet.
The browser loads the html (DOM) at first. The browser starts to load the external resources from top to bottom, line by line. If a <script> is met, the loading will be blocked and wait until the JS file is loaded and executed and then continue.
Solution(By Examveda Team)DOMContentLoaded and readystatechange are alternatives to the load event: they are triggered sooner, when the document and its elements are ready to manipulate, but before external resources are fully loaded.
If you put Javascript statements (rather than function definitions) inside a <script>
tag, they will be executed during page loading - before the onLoad event is fired.
<html>
<body>
<h2>First header</h2>
<script type="text/javascript">
alert("Hi, I am here");
document.write("<h3>This is Javascript generated</h3>");
</script>
<h2>Second header</h2>
</body>
</html>
The caveat is that you cannot search for elements by ID because these element might not have been rendered yet, so your ability to change the page that way is limited.
Bottom line: possible, not recommended.
What I usually do in such situations is as follows:
style="visibility:hidden;"
); visibility:visible
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With