android实现WebView中长按选中复制文本操作

啥都不说了,老司机直接移步GITHUB看源码吧:

https://github.com/deaboway/AndroidWebViewTextSelect

万一不work,一定不是代码的问题,你可以自查链接中的如下情况

CSS控制页面文字不能被选中user-select:none;

	body{
		-moz-user-select:none;/*火狐*/
		-webkit-user-select:none;/*webkit浏览器*/
		-ms-user-select:none;/*IE10*/
		-khtml-user-select:none;/*早期浏览器*/
		user-select:none;
	}

JS屏蔽复制粘贴右键菜单

	//屏蔽右键菜单
	document.oncontextmenu = function (event){
		if(window.event){
			event = window.event;
		}try{
			var the = event.srcElement;
			if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
			return false;
		}
			return true;
		}catch (e){
			return false;
		}
	}
	//屏蔽粘贴
	document.onpaste = function (event){
		if(window.event){
			event = window.event;
		}try{
			var the = event.srcElement;
			if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
			return false;
		}
			return true;
		}catch (e){
			return false;
		}
	}
	//屏蔽复制
	document.oncopy = function (event){
		if(window.event){
			event = window.event;
		}try{
			var the = event.srcElement;
			if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
			return false;
		}
			return true;
		}catch (e){
			return false;
		}
	}
	//屏蔽剪切
	document.oncut = function (event){
		if(window.event){
			event = window.event;
		}try{
			var the = event.srcElement;
			if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
			return false;
		}
			return true;
		}catch (e){
			return false;
		}
	}
	//屏蔽选中
	document.onselectstart = function (event){
		if(window.event){
			event = window.event;
		}try{
			var the = event.srcElement;
			if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
			return false;
		}
			return true;
		} catch (e) {
			return false;
		}
	}

参考:
1. https://www.cnblogs.com/icyhusky/p/6020548.html
2. https://github.com/deaboway/BTAndroidWebViewSelection
3. http://blog.csdn.net/qiushi_1990/article/details/73188110
4. http://blog.csdn.net/anjingzuo/article/details/51375544

欢迎关注我的微信公众号:

 

如无特殊说明,文章均为本站原创,转载请注明出处!

发表评论

邮箱地址不会被公开。 必填项已用*标注