`

iso UIWebView 禁用复制

    博客分类:
  • ios
 
阅读更多
为项目需要,需要在使用UIWebView载入html时,禁用在input中的copy paste Menu选项

修改Html页面

方法一:

function OnLoad()

{

   document.documentElement.style.webkitTouchCallout = "none"; //禁止弹出菜单

    document.documentElement.style.webkitUserSelect = "none";//禁止选中

}

然后在body加上onload

<body onload="OnLoad()"/>

实际测试,input并未禁止弹出复制、粘贴功能

html页面内容,禁止了复制功能

方法二:

<style type="text/css">
    *{
        -webkit-user-select: none; /* Disable selection/Copy of UIWebView */
    }
</style>
实际测试,禁止了弹出复制、粘贴功能,但键盘输入也无法在显示在webView的input中。


修改iOS代码:

方法一:

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    // Disable user selection
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
    // Disable callout
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
}

实际测试,input并未完成禁止弹出复制、粘贴功能

html页面内容,禁止了复制功能
方法二:

获得UIMenuController,然后强行隐藏menu item的view,

实际测试,有效果,估计不能提交到app store
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics