简体   繁体   中英

Why javascript 'window.location.hash' does not work in WKWebview in ios11?

it can work in ios10 or before , but it can not work in 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 = @"";
}

In iOS11, window.location.hash doesn't have support to scroll to location.

Please use following code for scroll web page to selected location

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM