I am trying to create a syntax highlighter script. I tried using my script on a code with 10 thousand lines and all I see is a blank page while it is loading. Everything will just show up after the script has finished it's task. By the way, I called my script inside the ready function of jQuery.
$(myFunction);
The script should execute after the page is fully rendered and the user can actually navigate through the page even if the script is not yet finished. The javascript will run in the background as it highlights the code one by one while not interfering the reponsiveness of the page. Thanks in advance.
EDIT:
To make this clearer, I would like to execute the code after everything is "rendered" not "loaded". Everything should already visible in the screen and the user can actually see the code come to life as it is being highlighted. Thanks.
If you are using an <script> inside <head> then use the onload attribute inside the <body> tag to Execute JavaScript after page load. It will run the function as soon as the webpage has been loaded.
The onload event occurs when an object has been loaded. onload is most often used within the <body> element to execute a script once a web page has completely loaded all content (including images, script files, CSS files, etc.).
But yes, it is an option.
Do you mean after all the images have been loaded?
I think window.onload is what you're looking for
window.onload = function() { //dom not only ready, but everything is loaded };
EDIT
Per Chris's comment, here's the jQuery way:
$(window).load(function() { //dom not only ready, but everything is loaded });
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