You can solve this problem in several ways.
The first step is to understand what you really need, in case you need only the data to validate the user login you can use JSONP
, making a simple request with the form data. Use JavaScript to get the values of Inputs
. You can also use a simple HTML return. To access this data you can use jQuery
. Using jQuery you can use the get pass user and password.
$.get( "dominio.com.br/login.php?usuario=" + usuario + "&senha=" + senha, function(dados) {
// Executa algum código com o resultado
});
With this you can log in and get the information in a simple way. You can also use POST
.
It should be made clear that when using JSON
or even JSONP
when making data requests through JavaScript you can find errors regarding CrossDomain, since your application does not have the same domain of content as this being accessed, WebKit tries to block this access. Search on Cross Domain
, JSONP
and CORS
for a better understanding on the subject.
If you really need to open SmarthPhone's browser to perform some type of authentication such as the Twitter
or Google
account you can create a window and store it in a variable, JavaScript can only close windows that it has Open. This way you just open the window, store in a variable and when the authentication is ok you simply close the window.
The example below makes this very clear, a window is opened and stored in a variable, so a Listener is created for the loadstop
event, this Listener defines that after 5 seconds the window should be closed.
In your case, verify that the authentication system supports a callback function or if it issues an event when authenticated, in this case you do not have to close after receiving the full load event, you can close it only when you receive the correct event. p>
var win = window.open( "http://docs.kendoui.com", "_blank", "EnableViewPortScale=yes" );
win.addEventListener( "loadstop", function() {
setTimeout(function() {
win.close();
}, 5000 );
});
Links that can help:
Cross Window Communication With Cordova's InAppBrowser
So, JSONP or CORS?
jQuery.get ()
Jquery Cross Domain Ajax