How do I close a webview?

I have an app that opens a WebView when you swipe right. But I cannot close the WebView once you are done with it. The goal is to allow the pressing of a back button on the bottom of Android Phones or if your on iOS swipe left to close the webview.

This is the code I have right now:

local recipePage = {} local function touchHandler(event) event.target:removeSelf() end function recipePage.openGIF(event) display.setStatusBar(display.HiddenStatusBar) local webView = native.newWebView(0, 0, display.contentWidth, display.contentHeight) webView.x = display.contentWidth \* 0.5 webView.y = display.contentHeight \* 0.5 webView:request(event.row.params.Website) webView:addEventListener("touch", touchHandler) widget = require("widget") end local function onKeyEvent(event) if (event.keyName == "back") then webView:removeSelf() end end Runtime:addEventListener("key", onKeyEvent) return recipePage

The problem is that the event handler for the back button on android phones does not see the reference of the webView. I come from a background in C# so I find this a little difficult. I don’t know how to remove the webView from a separate function. The same goes for iOS but it is extended by the fact that I have no idea how to listen for a swipe lift event on the entire screen.

Thanks in Advance, Bryce.

That’s because webView is local to the recipePage.openGIF(event) function. Other blocks of code outside that function cannot see it. This is called “Scope”.

Please read:

https://coronalabs.com/blog/2015/06/16/tutorial-scope-for-beginners/

Rob

That’s because webView is local to the recipePage.openGIF(event) function. Other blocks of code outside that function cannot see it. This is called “Scope”.

Please read:

https://coronalabs.com/blog/2015/06/16/tutorial-scope-for-beginners/

Rob