Webview does not read with some javascript codes

Asked

Viewed 45 times

0

I’m having a problem using Swift webview, I noticed that some javascript codes inside the loaded page do not run. Example:

onclick="functionMuitoLegal()"

But if I do the same thing using React on the page to load, onclick works normally within the webview:

onclick={functionMuitoLegal}

Has anyone ever faced this problem? You know why it occurs so that I can get around it ?

The url loads normally and the prints of this code below are being displayed on the Xcode console:

override func loadView() {
    let preferences = WKPreferences()
    preferences.javaScriptEnabled = true
    preferences.javaScriptCanOpenWindowsAutomatically = true
    let webConfiguration = WKWebViewConfiguration()
    webConfiguration.preferences = preferences

    webView = WKWebView(frame: .zero, configuration: webConfiguration)
    webView.navigationDelegate = self
    print("carrega delegate ")
    view = webView
}

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
  print("carregou página")
}

1 answer

0

I discovered the problem by reading the JS that the page ran, the onclick was working, the purpose of it was to run a JS function and submit a form, in the submission had a redirect coming from header that used http, as iOS only accepts https gave the impression that nothing happened.

Leave that answer here for if there’s anyone else with the same lack of attention as me.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.