为什么javascript 'window.location.hash'在ios11的WKWebview中不起作用?



它可以在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 = @"";
}

在ios11中,window.location.hash不支持滚动到位置。

请使用以下代码滚动网页到选定的位置

[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"var hashElement=document.getElementById('%@');if(hashElement) {hashElement.scrollIntoView();}", href]];

最新更新