Hi,
I have to call a web service submitting a web form with the POST method using InAppBrowser.
This web service redirects the browser to a page in which HTML I can read if the operation was successful or not.
So I have to pass a simple string from the browser to the app.
I’m using this code:
const pageContent = '<form name="redirect" id="redirect" action="' + dataUrl + '" method="post">' +
'<input type="hidden" name="PaReq" value="' + dataPareq + '">' +
'<input type="hidden" name="TermUrl" value="' + dataTermUrl + '">' +
'<input type="hidden" name="MD" value="' + dataPaymentId + '">' +
'</form> <script type="text/javascript">document.getElementById("redirect").submit();</script>';
const pageContentUrl = 'data:text/html;base64,' + btoa(pageContent);
const browserRef = this.iab
.create(
pageContentUrl ,
'_self',
'toolbar=yes,fullscreen=no,hidden=no,location=no,clearsessioncache=yes,clearcache=yes,zoom=no'
);
browserRef.executeScript({ code: 'localStorage.setItem("myresult", "OK" );'});
browserRef.on('loadstop').subscribe(event => {
const myResult = localStorage.getItem('myresult');
console.log(event);
alert(myResult);
...
}
In the InAppBrowser I write the variable myresult in the local storage, but when I read the same variable in the app it is null.
Why?
Is there a better way to do this?
Thank you very much
cld