Call a function before or after the API is fully loaded


cannon moyer

I have a button and if it is clicked, I need to call a function that hides another element initialized by a js file that is loaded asynchronously. However, the only way to hide an element is through the Javacsript API. There is no ID or class assigned to the iframe created through the API, so I'm forced to use the JS API for that script.

When my button is clicked, I execute the following code:

if(typeof Tawk_API.hideWidget === "function"){
  Tawk_API.hideWidget();
}else{
  Tawk_API.onLoad = function(){
      Tawk_API.hideWidget();
  };
}

The function successfully hides the widget if the widget is already loaded, or adds onLoad if it is not already loaded.

I know Javascript is not multi-threaded, but is it possible for the processor to hand off the main thread to the middle of my function to load the async js file, which could cause my condition to fail? I want to make sure jsthe file is not loaded during function execution, elsewhich will prevent the script from properly hiding the widget.

Tum

The Javascript engine will execute all synchronous code in a blocking fashion until an asynchronous operation (I/O, network calls, etc.) is reached. Then, after starting this asynchronous operation, it returns to execute more synchronous code. If the asynchronous operation completes during such synchronous code, the callback is only called when the blocking part has fully executed.

So your code is safe :)

Related


Call a function before or after the API is fully loaded

cannon moyer I have a button and if it is clicked, I need to call a function that hides another element initialized by a js file that is loaded asynchronously. However, the only way to hide an element is through the Javacsript API. There is no ID or class assi

Call a function before or after the API is fully loaded

cannon moyer I have a button and if it is clicked, I need to call a function that hides another element initialized by a js file that is loaded asynchronously. However, the only way to hide an element is through the Javacsript API. There is no ID or class assi

Call a function before or after the API is fully loaded

cannon moyer I have a button and if it is clicked, I need to call a function that hides another element initialized by a js file that is loaded asynchronously. However, the only way to hide an element is through the Javacsript API. There is no ID or class assi

Call a function before or after the API is fully loaded

cannon moyer I have a button and if it is clicked, I need to call a function that hides another element initialized by a js file that is loaded asynchronously. However, the only way to hide an element is through the Javacsript API. There is no ID or class assi

Call a function before or after the API is fully loaded

cannon moyer I have a button and if it is clicked, I need to call a function that hides another element initialized by a js file that is loaded asynchronously. However, the only way to hide an element is through the Javacsript API. There is no ID or class assi

Call a function before or after the API is fully loaded

cannon moyer I have a button and if it is clicked, I need to call a function that hides another element initialized by a js file that is loaded asynchronously. However, the only way to hide an element is through the Javacsript API. There is no ID or class assi

Call function after fully loaded in html with ng-repeate

Naresh How can I call the function after fully loading my json data from the server into ng-repeate? For example: I have json URL with some product data which is in my cart and once I click on view cart the cart items should be displayed in a popup. If you wan

Call function after fully loaded in html with ng-repeate

Naresh How can I call the function after fully loading my json data from the server into ng-repeate? For example: I have json URL with some product data which is in my cart and once I click on view cart the cart items should be displayed in a popup. If you wan

How to call a function after the page is fully loaded in Angular?

Akana I'm trying to call a function on a specific route after the page is fully loaded , like if the user logs in and goes to the main page route first, and successfully loads a function will call/call itself. constructor( private router: Router) { this.rout

Google Map API not fully loaded on second call

Arvind I'm using Google Maps displayed as a dialog, this control is dynamically added to the page multiple times. Now when I open the map for the first time it displays fine and I am able to select a location and use it. and many more. However, when I open the

Google Map API not fully loaded on second call

Arvind I'm using Google Maps displayed as a dialog, this control is dynamically added to the page multiple times. Now when I open the map for the first time it displays fine and I am able to select a location and use it. and many more. However, when I open the

Execute function after page is fully loaded in AngularJS

Torben Ludgau I want to execute this function as soon as the page is fully loaded. vm.pointInvoice = () => { if ($stateParams.property == "INVOICE") { vm.invoiceEdit($stateParams.checkin) vm.invoiceFocus = true; vm.receiptFocus =

Execute function after page is fully loaded in AngularJS

Torben Ludgau I want to execute this function as soon as the page is fully loaded. vm.pointInvoice = () => { if ($stateParams.property == "INVOICE") { vm.invoiceEdit($stateParams.checkin) vm.invoiceFocus = true; vm.receiptFocus =

Execute function after page is fully loaded in AngularJS

Torben Ludgau I want to execute this function as soon as the page is fully loaded. vm.pointInvoice = () => { if ($stateParams.property == "INVOICE") { vm.invoiceEdit($stateParams.checkin) vm.invoiceFocus = true; vm.receiptFocus =

Execute function after page is fully loaded in AngularJS

Torben Ludgau I want to execute this function as soon as the page is fully loaded. vm.pointInvoice = () => { if ($stateParams.property == "INVOICE") { vm.invoiceEdit($stateParams.checkin) vm.invoiceFocus = true; vm.receiptFocus =

Execute function after page is fully loaded in AngularJS

Torben Ludgau I want to execute this function as soon as the page is fully loaded. vm.pointInvoice = () => { if ($stateParams.property == "INVOICE") { vm.invoiceEdit($stateParams.checkin) vm.invoiceFocus = true; vm.receiptFocus =

Call the function after the page is loaded

Nitin I am using javascript in my html page. .I've been logging the time spent using the Navigation API. . When I try to find out the total load time (navigationStart-loadEventEnd), I find that loadEventEnd is 0. But also found that the loadEventStart value is

Call function after instruction is loaded

Shashank I am working on custom directives for angular 1.6 I want to call a function after loading instructions. Is there a way to do this? I tried the link function but it seems that the link function is executed before the load instruction. Any help would be

Call function after instruction is loaded

Shashank I am working on custom directives for angular 1.6 I want to call a function after loading instructions. Is there a way to do this? I tried the link function but it seems that the link function is executed before the load instruction. Any help would be

Call the function after the page is loaded

Nitin I am using javascript in my html page. .I've been logging the time spent using the Navigation API. . When I try to find out the total load time (navigationStart-loadEventEnd), I find that loadEventEnd is 0. But also found that the loadEventStart value is

Call function after AJAX is loaded

bull I have jQuery script that helps me to label rows in a table. I also have AJAX functionality to load other data into this table. My idea is that the Picker function is called every time after AJAX is used to tag that data. It works, but is very unstable -

Call function after instruction is loaded

Shashank I am working on custom directives for angular 1.6 I want to call a function after loading instructions. Is there a way to do this? I tried the link function but it seems that the link function is executed before the load instruction. Any help would be

Call function after instruction is loaded

Shashank I am working on custom directives for angular 1.6 I want to call a function after loading instructions. Is there a way to do this? I tried the link function but it seems that the link function is executed before the load instruction. Any help would be

Call function after AJAX is loaded

bull I have jQuery script that helps me to label rows in a table. I also have AJAX functionality to load other data into this table. My idea is that the Picker function is called every time after AJAX is used to tag that data. It works, but is very unstable -

How do I execute the function after the page is fully loaded?

Ben Shelock: After the page is fully loaded, I need to execute some JavaScript code. This includes things like images. I know you can check if the DOM is ready, but I don't know if this is the same as when the page is fully loaded. Matcha: called load. The pro

How do I execute the function after the page is fully loaded?

Ben Shelock: After the page is fully loaded, I need to execute some JavaScript code. This includes things like images. I know you can check if the DOM is ready, but I don't know if this is the same as when the page is fully loaded. Matcha: called load. The pro

Run a js function after all scripts on the page are fully loaded

PJW I'm trying to run a simple javascript function when the page is fully loaded. For example, this function: <script type="text/javascript"> function changeSize() { var el = document.getElementById("my-id"); el.style.height = "500px"; }; </script> My p

EmberJS component - run custom function after DOM is fully loaded

slap the key I'm trying to fully grasp the lifecycle of components. I've created a component, but I need a custom javascript function to run after the DOM is complete. I've gone through the EmberJS Docs and Stackoverflow, but none of the docs I've come across