Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

How to run a script once page is loaded

Avatar

Community Advisor

Hi,

How can we run a script once complete page is loaded.

Following is the scenario where we are facing the problem-

1.Created a teaser.

2.Inside which we are having a carousel component.

But the issue we are facing is carousel script is not working inside a carousel.

So is there a way we can run a script after page is loaded or using any listener.

 

Thanks

1 Accepted Solution

Avatar

Correct answer by
Administrator

Hi

As mentioned by Praveen you can use "window.onload" or

These solutions will also work:

<body onload="script();">

or

document.onload = function ...

or even

window.onload = function ...

Link:- http://stackoverflow.com/questions/807878/javascript-that-executes-after-page-load

 

Make sure not to use .ready(), as there is difference between .load and .ready.

$(document).ready(function() { // executes when HTML-Document is loaded and DOM is ready alert("document is ready"); }); $(window).load(function() { // executes when complete page is fully loaded, including all frames, objects and images alert("window is loaded"); });

I hope this helps you.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

View solution in original post

3 Replies

Avatar

Level 10

You can use:

function load() { console.log("Page is loaded, now perform task"); } window.onload = load;

Avatar

Correct answer by
Administrator

Hi

As mentioned by Praveen you can use "window.onload" or

These solutions will also work:

<body onload="script();">

or

document.onload = function ...

or even

window.onload = function ...

Link:- http://stackoverflow.com/questions/807878/javascript-that-executes-after-page-load

 

Make sure not to use .ready(), as there is difference between .load and .ready.

$(document).ready(function() { // executes when HTML-Document is loaded and DOM is ready alert("document is ready"); }); $(window).load(function() { // executes when complete page is fully loaded, including all frames, objects and images alert("window is loaded"); });

I hope this helps you.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni