它可以在ios10或之前使用,但它无法在ios11中运行?
- (void)jumpToHash:(WKWebView *)wkWebView {
NSString * jsJumpToHash =[NSString stringWithFormat:@"function jumpToHash(){window.location.hash ='#%@hash';};",self.hashLocation];
[wkWebView evaluateJavaScript:jsJumpToHash completionHandler:^(id Result, NSError * error) {}];
NSString *jsFun = @"jumpToHash()";
[wkWebView evaluateJavaScript:jsFun completionHandler:^(id Result, NSError * error) {}];
self.hashLocation = @"";
}
答案 0 :(得分:3)
在iOS11中,window.location.hash不支持滚动到位置。
请使用以下代码将滚动网页滚动到所选位置
[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"var hashElement=document.getElementById('%@');if(hashElement) {hashElement.scrollIntoView();}", href]];