3

I have a button in my Swift project,

Can I click the HTML button with the Swift button?

This is my Swift button:

@IBAction func buttonclick(_ sender: UIButton) {
    //click html button when click swift button
}

This is my HTML code:

<a id="htmlbutton" class="buton" onClick="clickbutton('data')" >Click</a>

I use wkWebView in my project and this html code from my website

Sorry for my bad English.

please check the image

screenshot

7
  • Possible duplicate of Convert HTML to NSAttributedString in iOS Commented Jun 23, 2018 at 15:49
  • Hi @Do2 I have found the similar question but there is no solution stackoverflow.com/questions/47523277/… Commented Jun 23, 2018 at 15:56
  • Did you read the answers on my link? Commented Jun 23, 2018 at 16:00
  • Yes, I did. I just want to click button in my website from swift button. Commented Jun 23, 2018 at 16:04
  • How would you do that? I don't understand. Give me an example... Commented Jun 23, 2018 at 16:07

1 Answer 1

3

You can manually trigger a click on the HTML button by injecting and running a JS script using WKWebView's evaluateJavaScript method. The script might look like this: document.getElementById('htmlbutton').click();.

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.