function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VenkateshVenkatesh 

Alternatives for window.onload() in salesforce lightning.?

Hi Team,

We have Using window.onload() to call a javascript function in salesforce classic. This works fine in classic. Now we have to migrate to lightning.
lightning won't support the window.onload(). Is there any alternative solution to fix this issue.
Any help would be appreciated.
Thank you. 
  
Raj VakatiRaj Vakati
You can do it like below ..

Move Your Onload login into the static resource .. use a <ltng:require> afterScriptsLoaded to handler any logic 

<ltng:require scripts="{!$Resource.***resourceName***}" afterScriptsLoaded="{!c.afterScriptsLoaded}" />

 
Raj VakatiRaj Vakati
Is its working ??
VenkateshVenkatesh
Hi Raj V,
         Can you please explain this with an example so that we can understand it more clearly.
Raj VakatiRaj Vakati
Can you share your window.onload()  code and i can rewrite for you . 
Max Alexander 19Max Alexander 19
<apex:page lightningStylesheets="true" showHeader="true" tabstyle="Opportunity" > <script> window.onload = new function() { window.location.href = '/006'; }; </script> <apex:form > </apex:form> <apex:ListViews type="Opportunity" > <apex:facet name="header"> &nbsp; </apex:facet> </apex:ListViews> </apex:page>

canyou help wiht this ne