How to send parameters to web app through webView.

Hello Everyone,

I have an app that in part, uses a webview to display an existing web application. There are multiple pages in that web app. What I want is when a user visits a particular page. e.g: there are three pages. 1. Home.  2. Services. 3.Contact

If a user clicks on the third link inside the webView, I want to send some data from corona to webView and perform some operation on that data in my web app.

Is there any possible way to do it?

Actually I want to send user location to my web portal only if he clicks some specific links inside the web View.

Please any help would be highly appreciated.

@RobMiracle maybe you can have a look and help me out…

Thanks,

You can send the location as part of the get parameter when you load the page. Something like home.html?lat=xxx&long=xxxx. I don’t know of a way to send value after the page is loaded.

I cannot send the parameters at the beginning. 

I did it but it’s neither efficient nor reliable.

function webListenerForBrowsers( event )     if event.url then        if(event.url == "http://app.example.com/distributors/Coupons.aspx") then     --locations.body = "lat=1234" --network.request("https://app.example.com/Distributors/SetSession.aspx", "POST", emailNetworkListener, locations)           if xVal == 0 then xVal = 1 webViewHome:request(event.url.."?val=done") end     end     end        if event.type == "loaded" then            if welcomeLoaded == false then        clearInitialStuff();        end     end        if event.errorCode then     if tostring(event.errorCode) ~= "-999"  then            native.showAlert( "Error!", "Internet Connection Appears To Be Offline.", { "OK" }, onComplete )     end     end     return true; end

Anyone there who can help?

Why can’t you send them at load and why isn’t it reliable? Do you get an error? I have never seen it fail unless there is some connectivity issue.

At the beginning user have to sign in first. And after that they are being redirected to coupons page.

Here I need to check the location where the coupon was clicked. Sometimes user will claim that the coupon was clicked here, I should be able to see that whether they are right or wrong.

Okay I did it. I captured the event.url and stopped the request and requested new url with location parameters and performed the same operation on that url.

Thanks,

You can send the location as part of the get parameter when you load the page. Something like home.html?lat=xxx&long=xxxx. I don’t know of a way to send value after the page is loaded.

I cannot send the parameters at the beginning. 

I did it but it’s neither efficient nor reliable.

function webListenerForBrowsers( event )     if event.url then        if(event.url == "http://app.example.com/distributors/Coupons.aspx") then     --locations.body = "lat=1234" --network.request("https://app.example.com/Distributors/SetSession.aspx", "POST", emailNetworkListener, locations)           if xVal == 0 then xVal = 1 webViewHome:request(event.url.."?val=done") end     end     end        if event.type == "loaded" then            if welcomeLoaded == false then        clearInitialStuff();        end     end        if event.errorCode then     if tostring(event.errorCode) ~= "-999"  then            native.showAlert( "Error!", "Internet Connection Appears To Be Offline.", { "OK" }, onComplete )     end     end     return true; end

Anyone there who can help?

Why can’t you send them at load and why isn’t it reliable? Do you get an error? I have never seen it fail unless there is some connectivity issue.

At the beginning user have to sign in first. And after that they are being redirected to coupons page.

Here I need to check the location where the coupon was clicked. Sometimes user will claim that the coupon was clicked here, I should be able to see that whether they are right or wrong.

Okay I did it. I captured the event.url and stopped the request and requested new url with location parameters and performed the same operation on that url.

Thanks,

That’s a good idea!

1 Like