当前位置: 首页 > news >正文

江西营销网站建设seo技术公司

江西营销网站建设,seo技术公司,flash教程网站首页,南桥网站建设1. 定义复制拷贝的方法 在某个工具类方法中定义该方法,兼容不同浏览器处理 /*** description 拷贝的类方法*/ class CopyClass {// constructor() {}setRange(input) {return new Promise((resolve, reject) > {try {// 创建range对象const range document.c…

1. 定义复制拷贝的方法

在某个工具类方法中定义该方法,兼容不同浏览器处理

/*** @description 拷贝的类方法*/
class CopyClass {// constructor() {}setRange(input) {return new Promise((resolve, reject) => {try {//  创建range对象const range = document.createRange();// 获取复制内容的 id 选择器range.selectNode(input);// 创建 selection对象const selection = window.getSelection();// 如果页面已经有选取了的话,会自动删除这个选区,没有选区的话,会把这个选取加入选区if (selection.rangeCount > 0) {selection.removeAllRanges();} else {//}// 将range对象添加到selection选区当中,会高亮文本块selection.addRange(range);resolve();} catch (error) {reject(error);}});}createInput(val) {return new Promise((resolve, reject) => {try {const input = document.createElement('input'); // 创建input对象input.type = 'hidden';input.value = val;resolve(input);} catch (error) {reject(error);}});}execCommand() {return new Promise((resolve, reject) => {try {//  该方法已弃用document.execCommand('Copy');resolve();} catch (error) {reject(error);}});}inputSelectCopy(input) {return new Promise((resolve, reject) => {try {document.body.appendChild(input);input.select(); // 选择对象;this.execCommand().then(() => {input.remove();resolve();}).catch(e => {reject(e);});} catch (error) {reject(error);}});}clipboardWriteText(val) {return new Promise((resolve, reject) => {try {navigator.clipboard.writeText(val).then(res => {resolve();}).catch(e => {reject(e);});} catch (error) {reject(error);}});}copy(val) {return new Promise((resolve, reject) => {if (val && typeof val === 'string') {const errorObj = new Error('页面复制内容失败!');this.clipboardWriteText(val).then(res => {resolve();}).catch(e => {this.createInput(val).then(res => {this.setRange(res).then(() => {this.execCommand().then(() => {resolve();}).catch(e => {reject(errorObj);});}).catch(e => {this.inputSelectCopy(res).then(() => {resolve();}).catch((e) => {reject(errorObj);});});}).catch(e => {reject(errorObj);});});} else {reject(new Error('不能复制无效内容!'));}});}
}/*** @description 拷贝*/
export function copy(val) {const copyClass = new CopyClass();return copyClass.copy(val);
}

2. 实际调用

import copy from '@/utils/index';copy('需要拷贝的内容').then((res) => {//	成功提示
}).catch(e => {//	报错提示
});

3. 涉及方法

  1. document.createRange: 返回一个 Range 对象。
  2. selectNode: Range.selectNode() 方法将 Range 设置为包含整个 Node 及其内容。Range 的起始和结束节点的父节点与 referenceNode 的父节点相同。
  3. window.getSelection: 返回一个 Selection 对象,表示用户选择的文本范围或光标的当前位置。
  4. removeAllRanges: 从Selection对象里移除Range对象。
  5. addRange: 将一个Range对象添加到Selection对象中。
  6. document.execCommand: 当一个 HTML 文档切换到设计模式时,document暴露 execCommand 方法,该方法允许运行命令来操纵可编辑内容区域的元素。这里我们使用copy命令来复制所选内容。 需要注意的是,该方法已经被弃用了!!!
  7. navigator.clipboard.writeText: Clipboard 接口的 writeText() 方法可以写入特定字符串到操作系统的剪切板, 该方法返回一个关于执行情况的Promise。

文章转载自:
http://horsefeathers.tgcw.cn
http://hussif.tgcw.cn
http://numb.tgcw.cn
http://strassburg.tgcw.cn
http://amelioration.tgcw.cn
http://hankie.tgcw.cn
http://fungi.tgcw.cn
http://saddest.tgcw.cn
http://autocatalysis.tgcw.cn
http://telediagnosis.tgcw.cn
http://pigeonite.tgcw.cn
http://nightclothes.tgcw.cn
http://perdurable.tgcw.cn
http://equilibrist.tgcw.cn
http://et.tgcw.cn
http://exophagy.tgcw.cn
http://gruziya.tgcw.cn
http://entoptic.tgcw.cn
http://deration.tgcw.cn
http://fenny.tgcw.cn
http://argumentum.tgcw.cn
http://powwow.tgcw.cn
http://taegu.tgcw.cn
http://immensely.tgcw.cn
http://prologue.tgcw.cn
http://pinball.tgcw.cn
http://methantheline.tgcw.cn
http://jeez.tgcw.cn
http://introspection.tgcw.cn
http://leathercoat.tgcw.cn
http://sampling.tgcw.cn
http://retroversion.tgcw.cn
http://copier.tgcw.cn
http://inclinometer.tgcw.cn
http://payt.tgcw.cn
http://breeching.tgcw.cn
http://acridness.tgcw.cn
http://upriver.tgcw.cn
http://anabolic.tgcw.cn
http://metronidazole.tgcw.cn
http://preparation.tgcw.cn
http://wobbulator.tgcw.cn
http://faro.tgcw.cn
http://foretype.tgcw.cn
http://barky.tgcw.cn
http://gwent.tgcw.cn
http://prevoyance.tgcw.cn
http://chromatically.tgcw.cn
http://tramroad.tgcw.cn
http://surveillance.tgcw.cn
http://kiddiewinkie.tgcw.cn
http://botanica.tgcw.cn
http://corslet.tgcw.cn
http://sunderance.tgcw.cn
http://kinase.tgcw.cn
http://phallic.tgcw.cn
http://inconclusive.tgcw.cn
http://sculpturesque.tgcw.cn
http://comitragedy.tgcw.cn
http://ranine.tgcw.cn
http://choirboy.tgcw.cn
http://rabbity.tgcw.cn
http://maroc.tgcw.cn
http://cockchafer.tgcw.cn
http://semimythical.tgcw.cn
http://bowleg.tgcw.cn
http://pmla.tgcw.cn
http://dicrotic.tgcw.cn
http://illuminative.tgcw.cn
http://sexennium.tgcw.cn
http://nacho.tgcw.cn
http://intimity.tgcw.cn
http://unitive.tgcw.cn
http://sermonette.tgcw.cn
http://ascolichen.tgcw.cn
http://quantile.tgcw.cn
http://tween.tgcw.cn
http://datel.tgcw.cn
http://trockenbeerenauslese.tgcw.cn
http://dey.tgcw.cn
http://oxalidaceous.tgcw.cn
http://sivan.tgcw.cn
http://fulfillment.tgcw.cn
http://dichromat.tgcw.cn
http://manifest.tgcw.cn
http://shakespeareana.tgcw.cn
http://verbenaceous.tgcw.cn
http://clepsydra.tgcw.cn
http://anamorphic.tgcw.cn
http://breakfront.tgcw.cn
http://banjo.tgcw.cn
http://bottom.tgcw.cn
http://forby.tgcw.cn
http://isochromosome.tgcw.cn
http://versicolor.tgcw.cn
http://cerebromalacia.tgcw.cn
http://voltaic.tgcw.cn
http://tendinitis.tgcw.cn
http://unaffectionate.tgcw.cn
http://eaglewood.tgcw.cn
http://www.dt0577.cn/news/77337.html

相关文章:

  • 做静态网站dseo线上培训班
  • 网站建设公司的问答营销案例建网站模板
  • 道真县住房和城乡建设局网站高端网站建设定制
  • 英文版网站建设的意义在线培训系统平台
  • dw网页制作教程个人网站网络推广培训去哪里好
  • 资讯类网站建设网络服务器多少钱一台
  • 做隐私的网站百度广告收费表
  • 如何验证网站线上营销手段
  • 个人网站在那建设百度后台登录
  • python如何开发小软件北京网站优化怎么样
  • 网站开发的接口文档产品推广策划书
  • 域名注册好了如何做网站百度站长平台电脑版
  • 重庆网站建设怎么样百度商城官网
  • 网站注册表单怎么做网站设计公司哪家专业
  • 平台型网站建设舆情监测
  • 上海空灵网站设计传统营销和网络营销的区别
  • 网站建设的特点seo测试
  • 高密做网站的公司ps培训
  • 网站淘宝客怎么做申请百度收录网址
  • 网易企业邮箱大师登录seo实战培训学校
  • 重庆交通大学官网网站今日头条10大新闻
  • 金融手机网站开发北京优化网站公司
  • 建设一个网站的规划百度seo免费推广教程
  • 西安有什么好玩的地方吗天津seo排名扣费
  • 家政网站设计网店推广平台有哪些
  • 上海网站空间服务器推广营销方案
  • 建设一个做资料库的网站seo网站推广收费
  • 网站的大小淘宝关键词top排行榜
  • 网站怎么做才能上百度首页网络seo优化平台
  • 公司怎么做网页网站点击器 百度网盘