简体   繁体   中英

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

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 for me: 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' " }); 
   });

Your problem isn't localStorage it's your string your variables are in your current script so you need to evaluate the variables before its sent to the new window like this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM