How I can pass a value in localStorage to InAppBrowser using executescript event

Hello! I have a problem with the plugin InAppBrowser.

I would like to insert a value stored in localStorage from my ionic app in a form on my website (username and password). It works fine with a simple value like ‘test’, but when I want to insert a value like localStorage.getItem(‘onlineIdStore’) nothing is happening. Do you have a solution?

I found a similar problem but the solution does not work: autologin-with-inappbrowser-on-an-external-website

Here is my code:

   var ref = window.open('website', '_blank', 'location=no');
   ref.addEventListener('loadstop', function(event) {
   ref.executeScript({ code: "document.getElementById('doc_login_username').value = 'test' " }); 
   });
1 Like

Here is the solution:

$scope.openCordovaWebView = function()
{

var ref = window.open('website', '_blank', 'location=no');

ref.addEventListener('loadstop', function(event) {
     
var username = "";
    if (localStorage.getItem("onlineIdStore") !== null) {
        username = localStorage.getItem("onlineIdStore");
    }

ref.executeScript({
            code: "document.getElementById('doc_login_username').value='"+username+"';"
        });  
    
});
};
1 Like

Hi!! I am facing one problem with InAppBrowser.

I need to pass the data to inAppBrowser by using post method, But am not having any idea about that. Do you have a solution???