TaufanBagusDPA
TaufanBagusDPA

Reputation: 25

How to hide div element in UIWebView Swift 3

I have code like this

func webViewDidFinishLoad(_ webView: UIWebView) {
        let loadStyles = "document.getElementById('platforms').style.display = 'none';"
        webView.stringByEvaluatingJavaScript(from: loadStyles)
    }

but it's not work in Frame UIWebView. I want to hide the div within the frame on UIWebView. If I change "alert('Hallo World')" in let LoadStyles this code call when app opened. I feel so confused.

please provide me with a solution if you can. Thanks

top up saldo paypal

Upvotes: 1

Views: 1538

Answers (2)

ucotta
ucotta

Reputation: 587

Use WKWebView, it is the modern version. Then you could use "evaluateJavaScript", it works perfect.

Read more in my response: https://stackoverflow.com/a/42239272/7565959

Upvotes: 1

kelin
kelin

Reputation: 11995

Using UIWebView isn't recommended in newest versions of iOS. That what Apple says:

Important

Starting in iOS 8.0 and OS X 10.10, use WKWebView to add web content to your app. Do not use UIWebView or WebView.

Try to implement the same thing using WKWebView, it works much better with js. I'm sure this will help.

Upvotes: 1

Related Questions