For my app I want to store the usernames that are entered into the local appdata.
I do not know how to store the value that is entered in the textbox from the webview to the localdata. Looking across the internet I also could not find any right answer.
I have read InvokeScriptAsync is a method that is used for this kind of things but there's not instruction on how to use it in my case.
I hope someone will have a solution for me.
Thanks in advance!
You can use InvokeScriptAsync to both inject javascript and retrieve html from WebView.
Here is the code to retrieve text entered by user in the WebView. Let consider username is the id of html input field and you want to retrieve what ever the text entered into that input by user.
string username = await MyWebView.InvokeScriptAsync("eval", new string[] { "document.getElementById('username').value;" });
This should called on NavigationCompleted callback method of WebView.
Related
I am trying to transfer a variable from one page using this code:
Edit
to the page login.html, and insert the variable(asdf in this example) to a textbox in the new page.
I have tried this code:
function NameFunction(name) {
document.getElementById("username").value = name;
}
It is not working. I think it doesn't work because thats another page.
If you want to pass parameters to another page you can put them using query string:
Edit
To get parameter on the login.html page you can use jQuery as it described here: Get escaped URL parameter
you can try using localStorage.
In you're onClick method, save the data you want to store in localStorage
localStorage.setItem(key,value);
When the new page loads, in the onLoad (ready function if using jquery) method get the data from localStorage and set it in the textbox
you can find more about localStorage in the following links
Storing Objects in HTML5 localStorage
http://www.w3schools.com/html/html5_webstorage.asp
and many more are available online
How do i save entered/ inputted text using JavaScript/ html.
What do I want:
Name or code etc to be entered in a box (prompt box eksample) and then I want it to be displayed/ printed on the page and I want it to remain there so other people that visit can see it.
What I have:
I have code that shows a prompt box where you can enter text then displays it in green. However what i want is for the entered text to remain on the website for others to see...
function mobCode() {
mobCode = prompt("Insert Code", "Code here");
document.getElementById("mC").innerHTML = mobCode;
document.getElementById("mC").style.color="green";
}
<p id="mC"> Mob Code </p>
<button type="button" onclick="mobCode()"> Click to Add </button>
What you will probably have to do is write a script that will send the entered input to a database you build which can store that information,and then have your js access the database to display it in a certain area of your page.
Check out this Q & A one of the answers is a nice article to help explain the idea behind it: Send data from javascript to a mysql database
If you want to deal easier with persistence of the data, instead of setting up database and using server side script you can look at Facebook's Parse. The free plan is quite usefull for small projects. There is a JavaScript SDK that can be used directly from your javascript code.
Also you can view statistics from the Parse dashboard.
Here is some saple code for example:
// Create a new Parse object
var Post = new ParseObject("Post");
var post = new Post();
// Save it to Parse
post.save({"title": "Hello World"}).then(function(object) {
alert("Yay! It worked!");
});
Basically I want the ff. done:
User inputs a text in my text field. If his text matches a text in my "list," he is sent to a certain URL once he hits the submit button.
I found a similar code on this site but his is just one specific text value. [ Get input text field from HTML into JavaScript and go to URL ]
I want mine to determine the user's text input from a list I provide. My list will have a lot of texts/urls and it will continue to grow, so manually inputting values into the script won't work for me.. I want to be able to edit the list (possibly in an admin panel or something?) instead of the js code.
Example:
input text: aaaa, go to URL1
input text: mmne, go to URL2
input text: lhfj, go to URL3
input text: tigf, go to URL4
input text: gred, go to URL5
Can anyone help me with this please? Thanks!
Hope this helps you
var Something =$("#TextBoxID").val();
if(Something == "aaaa")
{
window.location.href = 'URL1'; //Will take you to URL1
}
......
......
if you want to configure the list on an admin console you need to have some kind of server side technology like php (or node.js if you want to keep using javascript). You need to think of where this data will be stored. A possibility would be fetching the list of text/url pairs using ajax (e.g. with jQuery) and storing the data in some database or in your case also a plain text file probably would suffice. The functionality you are looking for is not possible with plain HTML and JavaScript on cient side.
Use a function like this, if you store your URLs on the client side (HTML/JS page):
function determineAndGoToURL(text) {
var url = "#";
switch(text) {
case "aaaa":
url="www.google.com";
break;
case "bbbb":
url = "www.bing.com";
break;
default:
url = "www.yahoo.com";
break;
}
window.location.href = "http://" + url;
}
If you have an updated list of URLs on the server side, get them from server-side to client side, and iterate over them with a for statement.
I'd suggest, you'd get them from the server as JSON, and use JSON.parse(text) to create an object out of them, and then iterate.
I am in the process of creating a simple webapp for which the user wouldn't have to input his credentials each time he opens the website (no possibility to save the password). I managed to find the form's fields and submit action and it is possible through Crome's console to login when the following lines are submitted.
document.getElementById('zonePwd').value="Password"
document.getElementById('zoneId').value="Id"
GInterface.traiterEvenementValidation()
Now, on my webapp, I'd like to know if it would be possible to do the same thing using strings after the user fills a dialog with both information.
Be sure to say so if I'm not clear enough
Thanks
PS: I'm very new with JS
I recommand you to create a javascript function like :
function setCredentials(id, pass)
{
document.getElementById('zonePwd').value=pass;
document.getElementById('zoneId').value=id;
GInterface.traiterEvenementValidation();
}
And then from your app code
String id = "myid"; //Get val from the dialog
String pass = "mypass"; //Get val from the dialog
webview.loadUrl("javascript:setCredentials('"+id+"','"+pass+"')");
Hope it helps ;)
I have a page with an html form. A third party application appends a hidden input in the form. How can i read this hidden input in my server side?
Alterantive, cause i dont know exactly the name of the hidden input, I want to be able to read the whole form in the server and then parse it. Is this possible?
I am using JSF and Java managed beans in the server side.
I have seen similar posts but nothing really helped me.
I am really newbie in Javascript , Ajax etc. so please be as much explanatory as possible :)
Thnx
I want to be able to read the whole form in the server and then parse it.
Essentially, your question boils down to How do I read all request parameters in JSF?, right?
Well, basically as follows:
Map<String, String[]> paramValues = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterValuesMap();
for (Entry<String, String[]> entry : paramValues.entrySet()) {
String name = entry.getKey();
for (String value : entry.getValue()) {
System.out.printf("Parameter: %s = %s%n", name, value);
}
}