Skip to content

Instantly share code, notes, and snippets.

@gbuesing
Last active February 8, 2016 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbuesing/da5f195289f1ec6b09e3 to your computer and use it in GitHub Desktop.
Save gbuesing/da5f195289f1ec6b09e3 to your computer and use it in GitHub Desktop.
// delare WKScriptMessageHandler as delegate
// add to WKWebViewConfiguration init:
configuration.userContentController.addScriptMessageHandler(self, name: "log")
// MARK: WKScriptMessageHandler
func userContentController(userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) {
if (message.name == "log") {
print(message.body)
}
}
function logObject(obj) {
window.webkit.messageHandlers.log.postMessage(obj);
}
document.addEventListener('turbolinks:load', function() { logObject( window.location.toString() ) }, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment