EagleH
EagleH

Reputation: 107

Click a Button in HTML with Swift

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

Upvotes: 3

Views: 2552

Answers (1)

dr_barto
dr_barto

Reputation: 6065

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();.

Upvotes: 3

Related Questions