I am loading local html content in a UIWebView. The javascript code for the downloaded content includes this event listener:
window.addEventListener("unload", function(){
This javascript code is executed only when (before) the UIWebView component is freed up (for example, when switching to another view controller), but it does not execute when another page loads. For instance:
document.addEventListener("click", function(){ document.location = "www.google.com"; }); window.addEventListener("unload", function(){ alert("bye bye"); });
If you execute this piece of code in safari when I click on a document, it will display a warning window before going to google.com. If I run the same code in UIWebView, the unloading listener will not execute. However, if I remove the UIWebView, the code will be executed.
My need is to have the same as Safari, that is, the upload method, which should also be executed when navigating away from the page.
source share