把每个网页自动生成二维码的方法更新:05-07 20:44 来源:万图网 分享:1850次 下一篇:没有了 - 二维码开始源於狗日的日本,这个东西真的是非常火的,特别是在移动安平台安卓手机上占有很多的市场,因为识别速度快存储信息多的缘故,现在买一个东西都只需要用手机轻松的拍一下了;看打开某一页网页,不需要记一大串的地址,只要手机一拍,就自动显示到手机上直接打开了。真的是非常的方便,现在很多博客上也都开始使用了,既然大家都开始使用,我们也就把他看做一个配套吧。二维码生成其实是很简单的,但是要是不管在哪个页面中都是同一个二维码就太不人性化了,今天提供的这段代码,可以轻松的根据当前所在 URL 地址自动生成匹配的二维码,不需要任何插件的帮助,只要把下面的代码直接放在网页代码中即可。
方法一: <style type="text/css"> .eweima{ width:200px; height:200px; margin:auto; } </style> <div class="eweima"> <script type="text/javascript"> document.write("<img src=\"https://chart./chart?cht=qr&chs=500x500&choe=UTF-8&chld=L|2&chl="); document.write(window.location.href); document.write("\" width=\"200\" height=\"200\" alt=\"二维码\"/>"); </script>
上面是所有代码,创建一个小工具把代码复制到里面就好了,代码中的 200 为二维码的高宽,高宽一定要一样,你可以根据自己的边栏宽度更改下。这套代码是利用了 google 的 API 实现的,所以速度上肯定是占优势的了。
--------------------------------------------------------------------------------
方法二: 一般网页中也可使用下面的代码:我用html测试OK。
<script> thisURL = document.URL; strwrite = "<img src='https://chart./chart?cht=qr&chs=150x150&choe=UTF-8&chld=L|4&chl=" + thisURL + "' width='150' height='150' alt='QR 码' />"; document.write( strwrite ); </script>
这个用的PHP代码中也可以使用下面的代码:
<img src=" the_permalink();?>" width="150" height="150" alt="QR 码" />
希望对大家能用到。
—————————————————————————————————————————— 织梦系统可直接用下面带边框的:
<!--二维码生成 --> <div class="zly1"><div class="zlx1"> <dl class="t11 l11"> <dt class='light'><strong>本页二维码</strong></dt> <dd class='light'> <ul class="nb1"> <style type="text/css"> .eweima{ width:200px; height:200px; margin:auto; } </style> <div class="eweima"> <script type="text/javascript"> document.write("<img src=\"https://chart./chart?cht=qr&chs=500x500&choe=UTF-8&chld=L|2&chl="); document.write(window.location.href); document.write("\" width=\"200\" height=\"200\" alt=\"二维码\"/>"); </script> </ul></dd> </dl> </div> </div> <!--二维码生成//-->
本文章转自万图网(www.) 详细出处参考:http://www./htm_Websj/htmlyuyan_101641554.html
|