WeChat h5 code scanning interface example: after scanning the code, the content is displayed in the input box

Test method: Save the following code to an htm file and put it on the server. Then send the URL of this html file to any friend on WeChat and click to access it.

Test effect: The test effect is as follows: click the scan code button on the page, scan it at any QR code or barcode, and the content will appear in the input box of the web page.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
    <title>微信h5扫码接口范例:扫码后内容显示到输入框</title>
</head>
 
<body>
<input type="text" id="erweima">
<a href="javascript:window.open('//996315.com/api/scan/?redirect_uri=' + encodeURIComponent(location.href), '_self');">Scan</a>

<script type="text/javascript">
var qr=GetQueryString("qrresult");
if(qr){
      
      
    document.all.erweima.value=qr;
}
 
function GetQueryString(name){
      
      
    var reg = new RegExp("\\b"+ name +"=([^&]*)");
    var r = location.href.match(reg);
    if (r!=null) return decodeURIComponent(r[1]);
}

</script>
</html>

Guess you like

Origin blog.csdn.net/sysdzw/article/details/132767255