# JavaScript events This section shows you how to process events from a JavaScript context to: - Pass the current environment parameters to the web view. - Terminate the current session and process commands. - Handle messages that should be processed by the host app. ## Inject environment parameters into WebView To pass the current environment parameters to the web view, you can simply load them as a JSON string. ```kotlin // JSON data to be injected into the WebView as JavaScript private const val JSON_DATA = """ window.zoomCampaignSdkConfig = window.zoomCampaignSdkConfig || { language: 'user language', firstName: 'user first name', lastName: 'user last name', nickName: 'user nick name', address: 'user address', company: 'user company', email: 'user email', phoneNumber: 'user phone number' }; """ // Inject JSON data as JavaScript into the WebView when the URL is loaded private fun injectJsonDataFunction() { val js = "javascript: $JSON_DATA;" binding.webView.loadUrl(js) } ``` > **Supported languages for language** > > `en-US`, `da-DK`, `de-DE`, `en-AU`, `en-GB`, `en-NZ`, `es-ES`, `es-MX`, `es-US`, `fr-CA`, `fr-FR`, `id-ID`, `it-IT`, `ja-JP`, `ko-KR`, `nl-NL`, `pl-PL`, `pt-BR`, `pt-PT`, `ro-RO`, `ru-RU`, `sv-SE`, `tr-TR`, `vi-VN`, `zh-CN`, `zh-TW` ## Handle exit callback functions To handle the termination of the current session and process commands from the JavaScript context, create a `JavascriptInterface` function. Here is an example. ```kotlin // Inject JavaScript handler functions into the WebView when the URL is loaded private fun injectJavaScriptFunction() { val js = """ javascript: window.addEventListener('zoomCampaignSdk:ready', () => { if (window.zoomCampaignSdk) { window.zoomCampaignSdk.native = { exitHandler: { handle: function() { $EXIT_HANDLER_NAME.handleExit(); } }, commonHandler: { handle: function(e) { $COMMON_HANDLER_NAME.handleCommon(JSON.stringify(e)); } } }; } }); """.trimIndent() binding.webView.loadUrl(js) } // JavaScript interface method to handle exit commands @JavascriptInterface fun handleExit() { //Your code } ``` ## Handle handoff events Create a `JavascriptInterface` to handle messages from the JavaScript context that the host app should process. ```kotlin // Inject handleHandoff function into the WebView when the URL is loaded private fun injectHandoffFunction() { val js = """ javascript: window.addEventListener('support_handoff', (e) => { $SUPPORT_HANDOFF_HANDLER_NAME.handleHandoff(JSON.stringify(e.detail)); }); """.trimIndent() binding.webView.loadUrl(js) } // JavaScript interface method to handle handoff commands @JavascriptInterface fun handleHandoff(e: String?) { //Your code } ```