Reputation: 4290
I am using webview load to detect when a page is loaded but i need it to only fire once but it fires many times i have come up with a solution below to get it fire once, but this will only happen once and once only i need it to fire every time a page is loaded but only once example.
webviewload = true;
webview.addEventListener('load', function() {
if(webviewload){
//run code to add stuff to webview this will run once
webview.remove(oldsidebar);
webview.add(newsidebar);
webviewload = false;
}
});
the above works fine for one webview load but if you run again it is obviously set to false so i can only run this code once. I found a hack that kind off works for me but i am looking for a better solution i understand its firing because it fires on every element load ads etc on webview.
webviewload = true;
webview.addEventListener('load', function() {
if(webviewload){
//run code to add stuff to webview this will run once
webview.remove(oldsidebar);
webview.add(newsidebar);
webviewload = false;
}
setTimeout(function(){
webviewload = true;
},5000)
});
ok above works but isn't ideal if the page take longer than 5 seconds to load etc i am getting problems. Can anyone give me a suggestion on how to fire webview load once then reset so i can run a block of code correctly. Hope this makes sense thanks
Upvotes: 1
Views: 1417
Reputation: 461
Yea, this is due to the fact that the page you are loading, like almost any portal homepage, is comprised almost fully of ajax calls to other pages and scripts, etc. This is going to cause your load event to fire, and fire, and fire again until everything is loaded.
I suppose one way around this would be listen for the load event and set some interval that if passed would kill the listener and carry on.
Upvotes: 1