Trouble with listener in newWebView

Hi, all. In my app I’m using a webView to display a page from a mobile site. It works fine with one small problem. On the mobile site’s page there is a back button which a user might confuse for the app’s true back button which is up at the top of the screen. If a user taps the mobile site’s back button the webView just disappears leaving a big empty space on the screen. The app’s navigation is still visable at the top, so it’s not fatal, but it’s not ideal either. 

I’ve tried setting up a listener to look for any sort of event triggered by clicking the mobile site’s back button. But I can’t detect any on the first screen, unless you navigate to a second screen on the mobile site and then the listener returns all the expected information. The back button there responds with an event type, “history.”

I also tried setting up an invisible button to capture the touch events right around the mobile site’s back button but that won’t work because all display objects site behind native ones.

I also tried capturing touch events by x,y coordinates, to no luck either.

I’m fairly stuck at this stage. Any thoughts would be greatly appreciated.

Here’s the basics of the code I’m dealing with:

[lua]

function webViewListener( event )

    

    print("Event type: "…event.type)

    print("URL: "…event.url)

    

    if event.errorCode then

        native.showAlert( “Error!”, event.errorMessage, { “OK” } )

    end

    if event.type == “history” then

        storyboard.gotoScene( “previous screen”, “slideRight”, 400  )

        webView:removeSelf()

        webView = nil

    end

end    

webView = native.newWebView( 0, 0, 320, 437)

webView:request( “http://m.airforce.com/recruiter-locator/” )

webView.anchorX, webView.anchorY = 0, 0

webView.y = 131

webView:addEventListener( “urlRequest”, webViewListener )

[/lua]

The webView is a native object and thats why you can’t overlay the Back and hide it etc. 

I tried your link in a regular desktop browser and same thing happens. Its a link leading to nowhere. I think its bad design on the part of the web developer putting that page together. Don’t think there is much you can do about it in Corona SDK. 

Ksan, thank you for looking at this. The moral support helps a lot even if there is no easy solution.

Since the back button isn’t registering any events, and loads a blank screen, I was hoping I could at least test to see if the webView == nil and then open the previous scene. Like this.

    if webView == nil then

        print(“Can’t go back. Open previous storyboard screen here instead.”)

    end

Right? But, sadly, another dead end.

You’re most welcome. Wish I had something else to contribute. Maybe others with more experience with the webView might have an idea. 

If the UI Docs at http://docs.coronalabs.com/guide/system/nativeUI/index.html#webview are correct, this might do the trick…

webView.canGoBack = false 

The webView is a native object and thats why you can’t overlay the Back and hide it etc. 

I tried your link in a regular desktop browser and same thing happens. Its a link leading to nowhere. I think its bad design on the part of the web developer putting that page together. Don’t think there is much you can do about it in Corona SDK. 

Ksan, thank you for looking at this. The moral support helps a lot even if there is no easy solution.

Since the back button isn’t registering any events, and loads a blank screen, I was hoping I could at least test to see if the webView == nil and then open the previous scene. Like this.

    if webView == nil then

        print(“Can’t go back. Open previous storyboard screen here instead.”)

    end

Right? But, sadly, another dead end.

You’re most welcome. Wish I had something else to contribute. Maybe others with more experience with the webView might have an idea. 

If the UI Docs at http://docs.coronalabs.com/guide/system/nativeUI/index.html#webview are correct, this might do the trick…

webView.canGoBack = false