js版:
<!DOCTYPE html>
<html>
<head>
<title>获取当前页面地址二维码</title>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
</head>
<body>
<div id="qrcode"></div>
<script>
$(function(){
$('#qrcode').qrcode({
width: 200,
height: 200,
text: window.location.href,
background: "#ffffff",
foreground: "#f00"
});
})
</script>
</body>
</html>
php版(需要依赖谷歌的服务,国内打不开):
<?php // Get current page URL $url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; // Generate QR code $qrcode = '<img src="https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl='.$url.'" title="QR code" />'; echo $qrcode; ?>