1

I have a web view in my view controller. In my web view there is a html form is load. Now when user input the value of form and press a button which is into view controller. After pressing the button I need those input value. How can I retrieve this value?

I try this way. but How can I get data?

override func viewDidLoad() {
    super.viewDidLoad()
    somec.loadRequest(URLRequest(url: URL(string: "https://tympanus.net/Tutorials/LoginRegistrationForm/")!))
}


@IBAction func getData(_ sender: Any) {
    let inputValue = somec.stringByEvaluatingJavaScript(from: "document.body.innerHTML")
    print(inputValue!)
}
2

1 Answer 1

2

To get value from username input try this:

let userNameValue = somec.stringByEvaluatingJavaScript(from: "document.getElementById('username').value")

for password value:

let passwordNameValue = somec.stringByEvaluatingJavaScript(from: "document.getElementById('password').value")

keys 'username' and 'password' are html input tag ids.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.