How to delay onLoad client script by 3 seconds to run.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 09:45 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 10:05 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 10:09 PM
you can use the set timeout as below.
setTimeout(function(){
g_form.setValue('category',''+cat);
g_form.setValue('subcategory', subCat);
}, 5000);
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 11:23 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 11:51 PM
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);
}
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak