When Jquery, Javascript Functions Are Called?
Solution 1:
OnLoad()
The onload
event occurs when an object has been loaded. Onload is most often used within the element to execute a script once a web page has completely loaded all content (including images, script files, CSS files, etc.).
Example (in HTML)
<element onload="myScript">
Example (in JavaScript)
object.onload = function(){myScript};
OnPageShow()
The onpageshow event occurs when a user navigates to a webpage. The onpageshow event is similar to the onload event, except that it occurs after the onload event when the page first loads. Also, the onpageshow event occurs every time the page is loaded, whereas the onload event does not occur when the page is loaded from the cache.
Example:
<body onpageshow="myFunction()">
Solution 2:
Onload Event
The DOM onload event in HTML occurs when an object has been loaded. The onload event is mostly used within the element, The <body>
The onload event can be used to check the browser type and browser version, and load the version of the web page based on the information. The onload event can also be used for cookies.
Example:
<!DOCTYPE html>
<html>
<head>
<title>
HTML DOM onload Event
</title>
</head>
<body>
<center>
<img src="https://contribute.geeksforgeeks.org/wp-content/uploads/GeeksforGeeksLogoHeader.png"
id="imgid">
<p id="pid"></p>
<script>
document.getElementById(
"imgid").addEventListener("load", GFGFun);
function GFGFun() {
document.getElementById("pid").innerHTML =
"Image loaded";
}
</script>
</center>
</body>
</html>
OnPageShow Event
The DOM onpageshow event in HTML occurs on navigating a webpage by the user.
the onload event does not occur when the page is loaded from the cache and onpageshow event occurs every time the page is loaded otherwise both the events are similar.
Example:
<!DOCTYPE html>
<html>
<head>
<title>
HTML DOM onpageshow Event
</title>
</head>
<body>
<center>
<h1 id="hID"
style="color:green">
</h1>
<h2>HTML DOM onpageshow Event</h2>
</center>
<script>
document.getElementsByTagName(
"BODY")[0].onpageshow = function() {
GFGfun()
};
function GFGfun() {
document.getElementById("hID").innerHTML =
"GeeksforGeeks";
};
</script>
</body>
</html>
Post a Comment for "When Jquery, Javascript Functions Are Called?"