How to delay onLoad client script by 3 seconds to run.

VIKAS MISHRA
Tera Contributor

I Have a onLoad client script which runs everytime when page gets loaded, 

Is there anything i can do so that this script will run 3 seconds letter when page is loading. 

Just wanted to add delay in the script.

4 REPLIES 4

Amitoj Wadhera
Kilo Sage

Hi @VIKAS MISHRA ,

 

You can refer to the below script:

var startTime = new Date().getTime();
                var delay = 3000; // Simulating a delay of 3 seconds
                while (new Date().getTime() < startTime + delay) {
                    // Waiting for 3 seconds
                }

 

If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.

 

Thanks,

Amitoj Wadhera

dgarad
Giga Sage

Hi @VIKAS MISHRA 

 you can use the set timeout as below.

setTimeout(function(){

g_form.setValue('category',''+cat);                
g_form.setValue('subcategory', subCat);
}, 5000);

 

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Mark Manders
Mega Patron

What's your reason for wanting this? You will have a page loaded and someone already working on it and you client scripts does what it needs to do, possibly reverting things already done. As an end user I wouldn't be happy with delays on client side functionality. 3 seconds is long for the average user.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Community Alums
Not applicable

Hi @VIKAS MISHRA ,

I tried your problem in my PDI and it works for me please use below script 

function onLoad() {
    //Type appropriate comment here, and begin script below
	alert("Outside delay");
    setTimeout(function() {
		alert("Inside  delay");
    }, 2000);

}

SarthakKashyap_0-1717656685268.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak