How to run a script once page is loaded | Community
Skip to main content
Ankur_Khare
Community Advisor
Community Advisor
March 16, 2016
Solved

How to run a script once page is loaded

  • March 16, 2016
  • 3 replies
  • 7345 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by kautuk_sahni

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

3 replies

smacdonald2008
Level 10
March 17, 2016

In page JSP, code a JQuery  https://api.jquery.com/load-event/ event.

edubey
Level 10
March 17, 2016

You can use:

function load() { console.log("Page is loaded, now perform task"); } window.onload = load;
kautuk_sahni
Community Manager
kautuk_sahniCommunity ManagerAccepted solution
Community Manager
March 17, 2016

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