首页 > 其他分享 >web 前端零散知识

web 前端零散知识

时间:2022-11-23 19:00:48浏览次数:47  
标签:function web none selection color 前端 js 零散 select

css 禁止选中

1 * {
2     -moz-user-select: none;
3     -webkit-user-select: none;
4     -ms-user-select: none;
5     -khtml-user-select: none;
6     -o-user-select: none;
7     user-select: none;
8 }

js 禁止选中

1 document.addEventListener("selectstart", function (e) {
2     e.preventDefault();
3 });

js 禁止通过快捷键打开开发者工具

1 document.addEventListener("keydown", function (e) {
2     if (e.key === "F12" || (e.ctrlKey && e.shiftKey && e.key === "I")) {
3         e.preventDefault();
4     }
5 });

js 禁用右键菜单

1 document.addEventListener("contextmenu", function (e) {
2     e.preventDefault();
3 });

js 查找匿名事件监听器

  1. getEventListeners(domElement) 可以得到该元素的全部事件监听器列表
  2. 重新定义 addEventListener

js 选区

 1 function select(dom) {
 2     if (!dom) return;
 3     if (
 4         dom instanceof HTMLInputElement ||
 5         dom instanceof HTMLTextAreaElement
 6     ) {
 7         dom.select();
 8     } else {
 9         const range = document.createRange();
10         range.selectNode(dom);
11 
12         const selection = window.getSelection();
13         if (selection.rangeCount > 0) {
14             selection.removeAllRanges();
15         }
16         selection.addRange(range);
17     }
18 }

js 复制

1 function copy() {
2     const text = window.getSelection().toString();
3     if (!text) return;
4     if (navigator.clipboard) {
5         navigator.clipboard.writeText(text);
6     } else {
7         document.execCommand("copy");
8     }
9 }

js 获取选区内容

window.getSelection().toString()

js 判断 PC 端还是移动端

  1. navigator.userAgent
  2. navigator.platform

css 设置选中文本的样式

 1 ::selection {
 2     background-color: #ff645d;
 3     color: white;
 4 }
 5 ::-moz-selection {
 6     background-color: #ff645d;
 7     color: white;
 8 }
 9 ::-webkit-selection {
10     background-color: #ff645d;
11     color: white;
12 }

js 通过字符串创建 html

1 function stringToHTML(str) {
2     var parser = new DOMParser();
3     var doc = parser.parseFromString(str, "text/html");
4     return doc.body;
5 }

css 定义滚动条

1 ::-webkit-scrollbar {
2     width: 8px;
3     height: 8px;
4 }
5 ::-webkit-scrollbar-thumb {
6     border-radius: 4px;
7     background: #aaa;
8 }

 

标签:function,web,none,selection,color,前端,js,零散,select
From: https://www.cnblogs.com/aurora-power/p/16919445.html

相关文章

  • 中了Viking,抓到CONFIG.EXE,NTDLL32.dll,webpnt.exe等
    endurer原创2007-04-05第1版昨天刚上班,一位同事说他的电脑反应很慢,让偶去检修。打开任务管理器,看到IEXPLORE.New之类的,肯定是中标了。下载pe_xscan扫描了log,重启电脑到带......
  • 常用的前端文件下载/上传实现思路
    下载此处仅讨论前端实现方式,不考虑附件形式,这需要后端配合。方式1:原生a链接/****@param{数据源,允许base64或Blob类型}fileSource*@param{文件名}}fi......
  • 攻防世界 web 难度2
    warmup知识点使用相对路径控制url读取方法//eee.php<?php$f=$_GET["file"];include($f);?><?phphighlight_file(__FILE__);classemmm{......
  • 【Web安全攻防从入门到精通】代码基础
    代码基础HTML基础HTML结构<!DOCTYPEhtml><!--声明为HTML5文档--><html><!--元素是HTML页面的根元素--><!--元素包含了文档的元(meta)数据<body>......
  • java web开发(和vue联合开发)
        前面我们谈到了很多次vue,也说到了vue的很多优点。比如说,vue实现了mvc中全部v的功能,也就是view的部分。这样,后端开发就变得很简单,前后端之间只要实现json数据的......
  • 前端-Avue属性解释
    Avue属性<template><!--基础组件--><basic-container><!--<el-button@click='exportHandle'>导出</el-button>--><avue-crud设置表格属性......
  • 模块化开发和webpack
    模块化开发和webpack模块化相关规范1、概述开发模式主要问题命名冲突文件依赖2、通过模块化解决上述问题模块化就是把单独的一个功能封装到-一个模块(文件)中,......
  • WebGoat部署到远端主机(注意事项)
    下载了一个WebGoat8.0版本,一开始在本机部署。但是想同时使用burpsuite,但是burpsuite要求jdk8.0。这个WebGoat8.0要求的jdk版本冲突。所以只能将WebGoat8.0部署到远端主机......
  • 纯前端根据JSON数据导出excel
     本文是草稿,具体文章内容待完善,如急需实现功能,可以加我好友告诉你vx:programmer-duan配置excel表头    配置字段  ......
  • 前端下载图片或pdf而不是预览方法
    一、下载pdf时使用 a 链接的 download 方法调用:this.downloadFile_2('文件名','url链接')本地无法下载的话,可以试试放到线上文件名要加 .pdf 后缀//fileName是......