I want to trigger one event on page load complete using javascript/jquery.
Is there any way to trigger event or call a simple function once page loading fully comple
You may also use the defer attribute in the script
tag.
As long as you do not specify async which would of course not be useful for your aim.
Example:
<script src="//other-domain.com/script.js" defer></script>
<script src="myscript.js" defer></script>
As described here:
In the above example, the browser will download both scripts in parallel and execute them just before DOMContentLoaded fires, maintaining their order.
[...] deferred scripts should run after the document had parsed, in the order they were added [...]
Related Stackoverflow discussions: How exactly does <script defer=“defer”> work?
Isn't
$(document).ready(function() {
});
what you are looking for?
The below code will call a function while the script is done loading
<html>
<body></body>
<script>
call();
function call(){ alert("Hello Word");}
</script>
</html>
$(document).ready(function() {
// do needed things
});
This will trigger once the DOM structure is ready.
$(document).ready( function() { YOUR CODE HERE } )
The windows.load function is useful if you want to do something when everything is loaded.
$(window).load(function(){
// full load
});
But you can also use the .load function on any other element. So if you have one particularly large image and you want to do something when that loads but the rest of your page loading code when the dom has loaded you could do:
$(function(){
// Dom loaded code
$('#largeImage').load({
// Image loaded code
});
});
Also the jquery .load function is pretty much the same as a normal .onload.