禁用長(zhǎng)按可選中文本
/* 已測(cè)有效 */
* {
-webkit-touch-callout:none;/*系統(tǒng)默認(rèn)菜單被禁用*/
-webkit-user-select:none;/*webkit瀏覽器*/
-khtml-user-select:none;/*早起瀏覽器*/
-moz-user-select:none;/*火狐瀏覽器*/
-ms-user-select:none;/*IE瀏覽器*/
user-select:none;/*用戶是否能夠選中文本*/
}
此段css樣式加入后能解決ios下手機(jī)瀏覽器,微信瀏覽器長(zhǎng)按出現(xiàn)選擇系統(tǒng)菜單問(wèn)題,但是對(duì)于Android下微信瀏覽器還會(huì)出現(xiàn)不兼容問(wèn)題。
禁止長(zhǎng)按彈出系統(tǒng)菜單
// 待測(cè)試
//oncontextmenu 事件在元素中用戶右擊鼠標(biāo)時(shí)觸發(fā)并打開上下文菜單,此處用于阻止菜單的出現(xiàn)。
//PC端 使右鍵和復(fù)制失效
document.oncontextmenu = new Function("event.returnValue=false");
document.onselectstart = new Function("event.returnValue=false");
//ios
document.oncontextmenu = function (e) {
e.preventDefault();
};
document.onselectstart = function (e) {
e.preventDefault();
};
//安卓
document.addEventListener('contextmenu', function (e) {
e.preventDefault();
});
document.ontouchend = function () {
throw new Error("NO ERRPR:禁止長(zhǎng)按彈出");
}
安卓UC瀏覽器上還需加入以下代碼,可以禁止長(zhǎng)按呼出菜單:
<!-- 待測(cè)試 -->
<!-- 安卓UC瀏覽器 禁用長(zhǎng)按 右鍵菜單 -->
<meta name="browsermode" content="application"/>