Created
August 21, 2018 23:42
-
-
Save dpawluk/7ed4be1e5395868f923ab10c820da883 to your computer and use it in GitHub Desktop.
This app shows that the window.onbeforeunload() event will fire and allow (some) functions to finish executing before the window is closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="utf-8"> | |
<!-- http://garden.zendesk.com --> | |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zendeskgarden/[email protected]" type="text/css"> | |
</head> | |
<body> | |
<h2 class="u-gamma">Hello, World!</h2> | |
<!-- https://github.com/zendesk/zendesk_app_framework_sdk --> | |
<script type="text/javascript" src="https://assets.zendesk.com/apps/sdk/2.0/zaf_sdk.js"></script> | |
<script> | |
// Initialise the Zendesk JavaScript API client | |
// https://developer.zendesk.com/apps/docs/apps-v2 | |
var client = ZAFClient.init(); | |
client.invoke('resize', { width: '100%', height: '200px' }); | |
client.on('app.registered', init); | |
function init(context){ | |
console.log(context); | |
makeTestRequest("app opened request"); | |
window.onbeforeunload = function(){ | |
makeTestRequest("app closed request"); | |
return null; | |
} | |
}; | |
function makeTestRequest(keyvalue){ | |
var req = { | |
url: "https://requestinspector.com/inspect/01cnfdfvgq1mhxq60bckws2bba", | |
type: "POST", | |
contentType: "application/json", | |
data: JSON.stringify({"testkey": keyvalue}) | |
} | |
client.request(req).then(function(response){ | |
console.log(response); | |
}); | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment