Click Copy micro-channel signal and go to the micro

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/wow_scott/article/details/102599804

To use resources

<link href="https://cdn.bootcss.com/mui/3.7.1/css/mui.min.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/mui/3.7.1/js/mui.min.js"></script>

The first step: Click the trigger must first select the target content

function selectText(textbox, startIndex, stopIndex) {
    if(textbox.createTextRange) {//ie
        var range = textbox.createTextRange();
        range.collapse(true);
        range.moveStart('character', startIndex);//起始光标
        range.moveEnd('character', stopIndex - startIndex);//结束光标
        range.select();//不兼容苹果
    }else{//firefox/chrome
        textbox.setSelectionRange(startIndex, stopIndex);
        textbox.focus();
    }
}

The second step, check the contents of the selected content will be copied to the clipboard and open a micro letter
which use the mui

function copyNum(){
    var NumClip=document.getElementById("header_wx");
    var NValue=NumClip.value;
    var valueLength = NValue.length;
    selectText(NumClip, 0, valueLength);
    if(document.execCommand('copy', false, null)){
        document.execCommand('copy', false, null)// 执行浏览器复制命令
        var titContent = '您已成功复制微信号,是否立即跳转到微信搜索该微信号,确认?';
     		var titInfo = '复制成功';
     		var btnArray = ['否', '是'];
        mui.confirm(titContent, titInfo, btnArray, function(e) {
	        if (e.index == 1) {
				var locatUrl = "weixin://";
				window.location.href = locatUrl;
	        }
	    })
    }
  }

html

<p class="header_info">微信号<input readonly="readonly" id="header_wx" value="15510750980"></input></p>

First this way, then skip to achieve click Copy micro letter

Guess you like

Origin blog.csdn.net/wow_scott/article/details/102599804