首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

关于iOS uiwebview 禁止弹出复制跟粘贴功能

2014-04-23 
关于iOS uiwebview 禁止弹出复制和粘贴功能因为项目需要,需要在使用UIWebView载入html时,禁用在input中的c

关于iOS uiwebview 禁止弹出复制和粘贴功能

因为项目需要,需要在使用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


热点排行