读书人

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

发布时间: 2014-04-23 16:50:13 作者: rapoo

关于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


读书人网 >操作系统

热点推荐