I have written some of the content for my app in HTML and I display it in my app using the native.newWebview. Within this HTML content, I have links to external web pages, for example https://google.com.
When a user clicks on the link in my app, I’d like my HTML pages to stay open in the app and for Google to open up in the device’s web browser.
However, what happens is that when they click on a link in my app, like Google, Google will open up in both my app and in the web browser.
As a note, in iOS, it seems the first time the link is clicked, it opens up in just the device’s default browser and not the app, but if you return to the app and click the link again it will open up in both the app and the browser. For Android it always opens up in both the app and in the browser.
Here is a simplified version of my code.
main.lua
local function webListener( event ) if event.url then system.openURL(event.url) end end htmlContent = native.newWebView( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight ) htmlContent:request( "links.html", system.ResourceDirectory ) htmlContent:addEventListener( "urlRequest", webListener )
And here is my internal HTML file that has the link:
links.html
\<html\> \<head\> \</head\> \<body\> Go to \<a href="https://google.com/"\>Google\</a\>. \</body\> \</html\>