6

I have an embedded WebView in my Cocoa application in which I load an external web page. Each time the user clicks on a button, the view opens and shows the page.

The problem is that the second time the user opens the WebView, the previous page is still visible. Instead I'd like to show a blank/empty page (together with a progress indicator).

How can I clear a WebView before loading a new page?

The closest solution I could find was to call this:

[webView stringByEvaluatingJavaScriptFromString:@"document.open();document.close()"];

Is there a better way to do this?

Thanks!

Mark
  • 1,447
  • 2
  • 14
  • 26

2 Answers2

20

Try this... Load "about:blank"

Dave
  • 875
  • 6
  • 15
3
[self.webView loadHTMLString:nil
                     baseURL:nil];

Worked for me nice.

Nikolay Shubenkov
  • 3,133
  • 1
  • 29
  • 31