0

we use <body onload="f1()"> for doing something onload

Is there anyway i can run a script f1 function after a page is loaded fully ??

Please answer with an example (jsfiddle preferred)

2
  • "Fully loaded" means all images are loaded? Commented Feb 24, 2014 at 7:50
  • jsfiddle preferred.....I think this is needed from your side. Commented Feb 24, 2014 at 7:51

4 Answers 4

1

The $(window).load(function() { event executes a bit later when the complete page is fully loaded, including all frames, objects and images

Using jQuery

<script>
$(window).load(function() {
    alert( "window loaded" );
    f1(); // Your function call
});
</script>

Using Pure JS

<script>
window.onload = function() {
    alert( "window loaded" );
    f1(); // Your function call
};
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

@LynAs, Just to confirm. As you have tagged jQuery. Is jquery loaded? I have updated answer to do using pure JS
1
 <script>
    f1();
 </script>

add this script before closing body tag i.e

</body>

1 Comment

I'm not sure, but I think this will run after all the DOM is loaded, but not necessarily after all the elements (stylesheets, scripts, objects, and especially images) are loaded, which is what I understand "fully loaded" means...
0

You can put your function inside $(window).load(function() { ... });:

$(window).load(function() {
    f1();
});

Code included inside $( window ).load(function() { ... }) will run once the entire page (images or iframes), not just the DOM, is ready.

Comments

0

Use the following method so that your function will be loaded nce a web page has completely loaded all content (including images, script files, CSS files, etc.).

<body onload="f1()">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.