You can use the webviewstring to transfer the username to the app. You will need to add some code to your javascript to set the webviewstring when the username is entered (no doubt you have a button event listener already from attempting localStorage)
You can then save the captured username in your app using tinyDB for later use, e.g. to pass the username back to the web page, also using the webviewstring.
Mmmmm,thanks.
So you mean in my javascript, if user name was input, then webviewer event becomes a trigger and it saved in TinyDB?
Do you know a specific example which I can refer to how to do it?
Here is a self contained example, using a local html file.
Click button to open web page.
Enter username.
Username is passed to the webviewstring and saved to the tinydb on pressing the Submit button
Open the web page again, and the saved username is returned to the web page
Click the Clear Username button to remove the username from the tinydb, and variables and reset the web page
This will only work when connected to a App Inventor companion app or with a compiled app. Computer browsers / jsFiddle do not know about webviewstring().
In your jsFiddle, if you comment out the webviewstring line, then the alert will show.
Now I see it.
Thank you so much for your support.
Could I ask you one more question?
I found custom webview can use browser cookie.
Can I save username into cookie and after closed apk app and open again,
I want to use the same user name which was already saved in a cookie.
And I added below code to load a username from TinyDB when I open website from MIT app.
var username = window.AppInventor.getWebViewString();
So if I input usename from MIT app, it looks like username was saved into Tiny DB because username is shown on the screen but once I close the application and re-start it,
next time username is not shown (blank).
I wonder if this is due to that username was not saved correctly or there is some problem to load username from TinyDB.