Webview and Outgoings

Greetings people,

I have simple problem. I couldn’t figure out with current https://docs.coronalabs.com/api/type/WebView/ and https://docs.coronalabs.com/api/library/network/request.html . I hope Corona have this ability.

I am making an application which will be an application for just a blog. I want to show the page of it but if the user click any link which: 1-Inside the blog  Result: Still stay inside of the application 2-Outside the blog Result: If it is an outgoing link, I want to take the user from the application and direct to any browser application as they please.

1-How can I check the click of a webpage which the user clicked?

2-How can I force a user to open a browser for that link? (But the page which is opened in application won’t change.)

Hi,
Can you share your sample Lua code here.I think you are missing something.
There is no need to get the event on webview, It works as of normal browsers.

Perhaps the webview methods are working on your history of browser & it takes forward & backward to the browser on the pages it viewed.
 

Assif

 

 local function onWebViewEvent(event) if "loaded" == event.type then native.setActivityIndicator( false ) else native.setActivityIndicator( true ) timer.performWithDelay( 3000, function() native.setActivityIndicator( false ) end, 1 ) end end local function onAlertComplete( event ) return true end function enterinternet( url) if networkConnection() == true then myApp.webView = native.newWebView(0, 0, display.contentWidth, display.contentHeight-145) myApp.webView:addEventListener("urlRequest", onWebViewEvent) myApp.webView:request( url ) else local alert = native.showAlert( programismi,"Şu anda ulaşılamıyor.", { "Tamam" }, onAlertComplete ) myApp.showScreen1() end myApp.webView.x = display.contentWidth/2 myApp.webView.y = (display.contentHeight-145)/2+65 end enterinternet("www.google.com")

This is the sample of it. Actually a changed version from popular business app sample from Corona. I need to put a code something like:
 

clickedurl = ???? (a code for it?) check = string.find( clickedurl, "www.google.com" ) if check == nil then ???? use a browser else --nothing. just goes on in webview surfing. end

Did you solve this?

Sadly no :confused: I was working on other sides of the application until I got an answer. I couldn’t find any code for them. I think there should be an event listener for it?

If you open a web page in a web view, any links you tap/click on should stay in the webView if you don’t take any further actions. You can use something like this:

 local function webListener(event) print("showWebPopup callback") local url = event.url if( string.find( url, "https:" ) ~= nil or string.find( url, "mailto:" ) ~= nil ) then print("url: ".. url) system.openURL(url) myApp.webView:back() end return true end

You can change what strings you’re searching for. This will give you an opportunity to get the URL and open it using system.openURL() which will open the device’s browser. However,  it still opens the link in the webView. I added an action to tell the webView to go back to the previous page, giving you the illusion that it’s behaving. I’m unaware of a way to prevent the webView from acting on the link.

Rob

Hi,
Can you share your sample Lua code here.I think you are missing something.
There is no need to get the event on webview, It works as of normal browsers.

Perhaps the webview methods are working on your history of browser & it takes forward & backward to the browser on the pages it viewed.
 

Assif

 

 local function onWebViewEvent(event) if "loaded" == event.type then native.setActivityIndicator( false ) else native.setActivityIndicator( true ) timer.performWithDelay( 3000, function() native.setActivityIndicator( false ) end, 1 ) end end local function onAlertComplete( event ) return true end function enterinternet( url) if networkConnection() == true then myApp.webView = native.newWebView(0, 0, display.contentWidth, display.contentHeight-145) myApp.webView:addEventListener("urlRequest", onWebViewEvent) myApp.webView:request( url ) else local alert = native.showAlert( programismi,"Şu anda ulaşılamıyor.", { "Tamam" }, onAlertComplete ) myApp.showScreen1() end myApp.webView.x = display.contentWidth/2 myApp.webView.y = (display.contentHeight-145)/2+65 end enterinternet("www.google.com")

This is the sample of it. Actually a changed version from popular business app sample from Corona. I need to put a code something like:
 

clickedurl = ???? (a code for it?) check = string.find( clickedurl, "www.google.com" ) if check == nil then ???? use a browser else --nothing. just goes on in webview surfing. end

Did you solve this?

Sadly no :confused: I was working on other sides of the application until I got an answer. I couldn’t find any code for them. I think there should be an event listener for it?

If you open a web page in a web view, any links you tap/click on should stay in the webView if you don’t take any further actions. You can use something like this:

 local function webListener(event) print("showWebPopup callback") local url = event.url if( string.find( url, "https:" ) ~= nil or string.find( url, "mailto:" ) ~= nil ) then print("url: ".. url) system.openURL(url) myApp.webView:back() end return true end

You can change what strings you’re searching for. This will give you an opportunity to get the URL and open it using system.openURL() which will open the device’s browser. However,  it still opens the link in the webView. I added an action to tell the webView to go back to the previous page, giving you the illusion that it’s behaving. I’m unaware of a way to prevent the webView from acting on the link.

Rob