CodeIgniter Forums
Jquery problem with .unload - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Jquery problem with .unload (/showthread.php?tid=73704)



Jquery problem with .unload - richb201 - 05-24-2019

I have the code below that I use to tell my Chrome Extension to go into a special "mode". Here is the code from the view:

<script language="javascript">

   $(document).ready( function() {
       var editorExtensionId = "lamacgnkfoiknjpleghfknfigbmhdaei";
       // unload when done
       $(window).unload(function(){
           chrome.runtime.sendMessage(editorExtensionId, "snapshot_mode_unload",
       })


       // Make a simple request:
       chrome.runtime.sendMessage(editorExtensionId, "snapshot_mode",
           function (response) {
               if (!response.success)
                   handleError(url);

           }
       )
   })

</script>


When I comment out the .unload code it seems to run fine. I get the message in the extension and act upon it. However, when I uncomment the .unload code neither  the load message is not being sent nor is the unload message. It just breaks. Any jquery people up here? Also, is there a way to pass in a parameter from my ci controller to the javascript function?


RE: Jquery problem with .unload - InsiteFX - 05-24-2019

Your missing the last closing )

Code:
 chrome.runtime.sendMessage(editorExtensionId, "snapshot_mode_unload",

Should be:

Code:
 chrome.runtime.sendMessage(editorExtensionId, "snapshot_mode_unload"),



RE: Jquery problem with .unload - richb201 - 05-26-2019

The following worked:

$(window).on('beforeunload',(function(){
chrome.runtime.sendMessage(editorExtensionId, "snapshot_mode_unload")