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
SANKET KUMAR 28SANKET KUMAR 28 

Lightning Alternative of Window.Open() method, Window.Close() and window.onload() method in a Visualforce Page that is used in Lightning

When you run a Lightning experience readiness report, you will get a note that windows function will not work in Lightning.
function Close1(){
        window.close();
    }


I tried with apex:outputlink, sforce.one.navigation but the issue is when we redirect to the parent page from the child page, it gives a refreshed view of the parent page. But I have the scenario to keep the current state of parent and just close the child page tab.
One more thing, when we tried with apex:outputlink, we are not able to set the width and height of window, How we can achieve that?

similarly,
window.onload():- 
What is the tag available for Vf page that we can replace window.onload() using that tag ?
NagendraNagendra (Salesforce Developers) 
Hi Sanket,

Sorry for this issue you are facing.

For window.onload() 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}" />

Thanks,
Nagendra
Ahmed Ansari 13Ahmed Ansari 13
Hello SANKET KUMAR 28,

for this workaround to use vf page in both classic and lightning you can 

write javascript function like this
function goto(){
if( (typeof sforce != 'undefined') && (sforce != null) ) {
               
              sforce.one.navigateToURL('url', true);
               
            } else {
                window.top.location.href = "url"; 
            }
}

sfoce differentiate lightning and classic experience in vf page
SANKET KUMAR 28SANKET KUMAR 28
Hi @Nagendra, Thanks for your answer. I have doubt ltng:require will work in vf page? i think you have provided an answer for the Lightning component. correct me if I am wrong.