How to clear back forward list in UIWebview on iPhone?

前端 未结 8 475
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-10 13:09

I want to access/clear the back forward list as if the UIWebView is new again. Is there any public API or workaround to do this?

I\'ve tried:

         


        
8条回答
  •  星月不相逢
    2020-12-10 14:01

    I was successful (as far as you can call such a workaround 'successful') using the following line of code:

    [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"if( window.history.length > 1 ) { window.history.go( -( window.history.length - 1 ) ) }; window.setTimeout( \"window.location.replace( '%@' )\", 300 );", targetLocation]];
    

    where targetLocation is the desired URL as a NSString.

    What it does is to tell the browser to go as far backwards as the history goes and then, after a short timeout, load the desired URL.

    This of course does not solve the problem of clearing the forward going history (which I didn't need in my case).

提交回复
热议问题