如何从UIWebview中删除选择? [重复]

时间:2022-08-25 00:05:41

This question already has an answer here:

这个问题在这里已有答案:

In my iPhone app,I am using a web view in a view controller. When I press and hold the screen,some selections come on webview, at times a action sheet comes which has "copy" and "cancel" buttons

在我的iPhone应用程序中,我在视图控制器中使用Web视图。当我按住屏幕时,一些选项出现在webview上,有时会出现一个带有“复制”和“取消”按钮的操作表

How to remove this ?

如何删除?

如何从UIWebview中删除选择? [重复]

2 个解决方案

#1


3  

you can disable the selection by using this code

您可以使用此代码禁用选择

[webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none'; document.body.style.KhtmlUserSelect='none'"];

if you using Jscript in your web page then this could do the trick

如果你在你的网页中使用Jscript,那么这可以解决问题

[webView stringByEvaluatingJavaScriptFromString:@"window.getSelection().removeAllRanges();"];

if you want to disable copy paste then this could do the trick

如果你想禁用复制粘贴,那么这可以解决问题

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender 
{    
    if (action == @selector(copy:) ||
        action == @selector(select:)||
        action == @selector(paste:)||
        action == @selector(cut:)) 
    {
        return NO;
    }
    return [super canPerformAction:action withSender:sender];
}

OR

 webView.userInteractionEnabled=NO; // in case you need to disable whole UIWebView

#2


0  

If you are using .css, you can add these to the appropriate style

如果您使用的是.css,则可以将它们添加到适当的样式中

    *.noselect {
            -webkit-user-select:none;
            -webkit-touch-callout:none;
    }

#1


3  

you can disable the selection by using this code

您可以使用此代码禁用选择

[webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none'; document.body.style.KhtmlUserSelect='none'"];

if you using Jscript in your web page then this could do the trick

如果你在你的网页中使用Jscript,那么这可以解决问题

[webView stringByEvaluatingJavaScriptFromString:@"window.getSelection().removeAllRanges();"];

if you want to disable copy paste then this could do the trick

如果你想禁用复制粘贴,那么这可以解决问题

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender 
{    
    if (action == @selector(copy:) ||
        action == @selector(select:)||
        action == @selector(paste:)||
        action == @selector(cut:)) 
    {
        return NO;
    }
    return [super canPerformAction:action withSender:sender];
}

OR

 webView.userInteractionEnabled=NO; // in case you need to disable whole UIWebView

#2


0  

If you are using .css, you can add these to the appropriate style

如果您使用的是.css,则可以将它们添加到适当的样式中

    *.noselect {
            -webkit-user-select:none;
            -webkit-touch-callout:none;
    }