问题描述
我正在从网络加载一些内容到 UIWebView
,但我希望在 UIWebView
中禁用所有链接.这可能吗?我可以解析文本,但我正在寻找更简单的东西.
I am loading some content from the web into a UIWebView
, but I'd like all links to be disabled in the UIWebView
. Is this possible? I could parse the text, but I'm looking for something easier.
推荐答案
你可以给 UIWebView
一个 delegate 并实现 -webView:shouldStartLoadWithRequest:navigationType:
委托方法return NO;
(初始加载除外).
You can give the UIWebView
a delegate and implement the -webView:shouldStartLoadWithRequest:navigationType:
delegate method to return NO;
(except on the initial load).
这将阻止用户查看除该单页之外的任何内容.
That will prevent the user from viewing anything but that single page.
要提供评论中要求的示例...以 allowLoad=YES
开头,然后:
To provide an example requested in the comments... Start with allowLoad=YES
and then:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
return allowLoad;
}
- (void)webViewDidFinishLoad:(UIWebView*)webView {
allowLoad = NO;
}
这篇关于禁用 UIWebView 中的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!