生成二维码,可以使用jquery的qrcode插件。但是使用html5 canvas或svg生成,在有的手机上无法保存,而且也无法兼容对html5支持不好的浏览器。此处我们使用node express后端直接生成二维码。
var express = require('express');
var app = express();
var qr_image = require('qr-image');
app.get('/qrcode',function(req,res){
var temp_qrcode = qr_image.image('http://www.baidu.com');
res.type('png');
temp_qrcode.pipe(res);
})
app.listen(80);
然后前端使用
<img src='http://localhost/qrcode' />