Search code examples
iosswiftxcodewkwebviewbrowser-history

Clear WKWebView history to avoid going back and forward in browsing history


I'm using the newest version of Xcode and Swift.

I'm using a WKWebView to load content from my web server.

You can swipe to go back and forward in the history of web pages you visited.

There's also a button to go back to the home page.

I additionally want to clear the history/backForwardList, so it's impossible to go back or forward, since this is the expected behavior when you reset the current view.

How can I do that?


Solution

  • As such, there is no method defined by Apple to do so but if you really wish to implement this functionality, I would suggest you just reinitialize your WKWebView.

    webView = WKWebView()

    I did this in my app but one thing to note is that you will have to reset all your constraints again.