<!DOCTYPE html>
	<html lang="vi" xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#">
	<head>
<title>Tạo QR Code với HTML5 - JavaScript</title>
<meta name="description" content="Tạo QR Code với HTML5 - JavaScript - Savefile - Tin Tức - http&#x3A;&#x002F;&#x002F;phanmemthienha.com&#x002F;news&#x002F;savefile&#x002F;huong-dan-phan-mem&#x002F;tao-qr-code-voi-html5-javascript-119.html">
<meta name="author" content="PHAN MEM THIEN HA">
<meta name="copyright" content="PHAN MEM THIEN HA [phamhuy842005@gmail.com]">
<meta name="robots" content="index, archive, follow, noodp">
<meta name="googlebot" content="index,archive,follow,noodp">
<meta name="msnbot" content="all,index,follow">
<meta name="generator" content="NukeViet v4.0">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:title" content="Tạo QR Code với HTML5 - JavaScript">
<meta property="og:type" content="website">
<meta property="og:description" content="Savefile - Tin Tức - http&#x3A;&#x002F;&#x002F;phanmemthienha.com&#x002F;news&#x002F;savefile&#x002F;huong-dan-phan-mem&#x002F;tao-qr-code-voi-html5-javascript-119.html">
<meta property="og:site_name" content="PHAN MEM THIEN HA">
<meta property="og:url" content="http://phanmemthienha.com/news/huong-dan-phan-mem/tao-qr-code-voi-html5-javascript-119.html">
<link rel="shortcut icon" href="http://phanmemthienha.com/uploads/logo-shop-thien-ha-5.png">
<link rel="canonical" href="http://phanmemthienha.com/news/huong-dan-phan-mem/tao-qr-code-voi-html5-javascript-119.html">
<link rel="alternate" href="http://phanmemthienha.com/news/rss/" title="Tin Tức" type="application/rss+xml">
<link rel="alternate" href="http://phanmemthienha.com/news/rss/huong-dan-phan-mem/" title="Tin Tức - Hướng dẫn phần mềm" type="application/rss+xml">
<link rel="alternate" href="http://phanmemthienha.com/news/rss/huong-dan-noi-bo/" title="Tin Tức - Hướng dẫn nội bộ" type="application/rss+xml">
<link rel="alternate" href="http://phanmemthienha.com/news/rss/Doi-tac/" title="Tin Tức - Đối tác" type="application/rss+xml">
<link rel="alternate" href="http://phanmemthienha.com/news/rss/Tuyen-dung/" title="Tin Tức - Tuyển dụng" type="application/rss+xml">
<link rel="preload" as="script" href="http://phanmemthienha.com/assets/js/jquery/jquery.min.js">
<link rel="preload" as="script" href="http://phanmemthienha.com/assets/js/language/vi.js">
<link rel="preload" as="script" href="http://phanmemthienha.com/assets/js/global.js">
<link rel="preload" as="script" href="http://phanmemthienha.com/themes/default/js/news.js">
<link rel="preload" as="script" href="http://phanmemthienha.com/themes/popovleather/js/main.js">
<link rel="preload" as="script" href="http://phanmemthienha.com/themes/popovleather/js/bootstrap.min.js">
<link rel="StyleSheet" href="http://phanmemthienha.com/assets/css/font-awesome.min.css">
<link rel="StyleSheet" href="http://phanmemthienha.com/themes/popovleather/css/bootstrap.min.css">
<link rel="StyleSheet" href="http://phanmemthienha.com/themes/popovleather/css/style.css">
<link rel="StyleSheet" href="http://phanmemthienha.com/themes/popovleather/css/style.responsive.css">
<link rel="StyleSheet" href="http://phanmemthienha.com/themes/default/css/news.css">
<link rel="StyleSheet" href="http://phanmemthienha.com/assets/css/popovleather.vi.0.css?t=87">
<style>
	body{background: #fff;}
</style>
	</head>
	<body>
<div id="print">
	<div id="hd_print">
		<h2 class="pull-left">PHAN MEM THIEN HA</h2>
		<p class="pull-right"><a title="PHAN MEM THIEN HA" href="http://phanmemthienha.com/">http://phanmemthienha.com</a></p>
	</div>
	<div class="clear"></div>
	<hr />
	<div id="content">
		<h1>Tạo QR Code với HTML5 - JavaScript</h1>
		<ul class="list-inline">
			<li>Chủ nhật - 31/03/2019 00:48</li>
			<li class="hidden-print txtrequired"><em class="fa fa-print">&nbsp;</em><a title="In ra" href="javascript:;" onclick="window.print()">In ra</a></li>
			<li class="hidden-print txtrequired"><em class="fa fa-power-off">&nbsp;</em><a title="Đóng cửa sổ này" href="javascript:;" onclick="window.close()">Đóng cửa sổ này</a></li>
		</ul>
		<div class="clear"></div>
		<div id="hometext">
			Hướng dẫn tạo mã QR với JavaScript, Canvas, HTML5, tương thích với tất cả các web-browser hiện đại. Cách hiện thực này không tốn kém quá nhiều năng lực của web-server.
		</div>
		<div id="bodytext" class="clearfix">
			QR Code với JavaScript<br  />
Cài đặt<br  />
Download qrcode.min.zip và giải nén được file <a href="https://www.stdio.vn/statics/external_data/files/pages/articles/2015/215/content/qrcode.min.zip" target="_blank">qrcode.min.js</a> up load file này lên web-server của bạn (bạn có thể download từ website gốc của nhà phát triển Sangmin Shim tại https://github.com/davidshimjs/qrcodejs<br  />
Tại tag head trong phần html, bạn hãy load script vào như cách ta load 1 file javascript vào file html. Lưu ý dòng số 1, do sử dụng HTML5 Canvas để vẽ QR Code nên ta cần thông báo cho trình duyệt biết phiên bản HTML ta đang sử dụng là HTML5 &lt;!DOCTYPE HTML&gt;.
<pre>
<code class="language-html">    &lt;!DOCTYPE html&gt;
    &lt;html&gt;
    	&lt;head&gt;
    		&lt;script type=&quot;text/javascript&quot; src=&quot;/qrcode.min.js&quot;&gt;
    	&lt;/head&gt;
    	&lt;body&gt;
    	...
    	&lt;/body&gt;
    &lt;/html&gt;</code></pre>
Tại vị trí trong tag body, bất kể ở đâu mà ta muốn mã QR sẽ hiện lên, ta sẽ đặt tag sau

<pre>
<code class="language-html">&lt;div id=&quot;id_qrcode&quot;&gt;&lt;/div&gt;</code></pre>
Ví dụ (xem dòng số 9)

<pre>
<code class="language-html">    &lt;!DOCTYPE html&gt;
    &lt;html&gt;
    	&lt;head&gt;
    		&lt;script type=&quot;text/javascript&quot; src=&quot;qrcode.min.js&quot;&gt;&lt;/script&gt;
    	&lt;/head&gt;
    	&lt;body&gt;
    	&lt;h1&gt;Hien thi QR Codes boi Stdio&lt;/h1&gt;
    	&lt;p&gt;
    		&lt;div id=&quot;id_qrcode&quot;&gt;&lt;/div&gt;
    	&lt;/p&gt;
    	&lt;/body&gt;
    &lt;/html&gt;</code></pre>
<span style="font-size:20px;">Tạo QR Codes</span><br  />
Sau khi trang được load xong (onload) bạn có thể gọi thực thi việc tạo QR Code với nội dung mong muốn
<pre>
<code class="language-html">    var qrcode = new QRCode(&quot;id_qrcode&quot;, {
    	text:&quot;www.stdio.vn&quot;,
    	width:100,
    	height:100,
    	colorDark:&quot;#000000&quot;,
    	colorLight:&quot;#ffffff&quot;,
    	correctLevel:QRCode.CorrectLevel.H
    });</code></pre>
Bạn có thể thay thế dòng số 2 với nội dung www.stdio.vn thành nội dung mà bạn muốn. Bạn cũng có thể thay đổi kích thước width, height như mong muốn.<br  />
Tham khảo<br  />
https://github.com/davidshimjs/qrcodejs - 31/3/2015<br  />
Download demo hoàn chỉnh <a href="https://drive.google.com/file/d/15VpIYwTu_UfF4dJMMXNIMPJsXF-pbLW_/view?usp=sharing" target="_blank">DOWNLOAD QR_CODE_DEMO.zip</a><br  />
<br  />
Bổ xung hàm lấy thông tin từ dường dẫn URL. có thể áp dụng trong&nbsp; việc lấy dữ liệu do qrcode tạo ra bằng method GET
<pre>
<code >
&lt;!----------ham lay tham so duong dan trang web begin------&gt;
		var getUrlParameter = function getUrlParameter(sParam) {
		var sPageURL = decodeURIComponent(window.location.search.substring(1)),
        sURLVariables = sPageURL.split(&#039;&amp;&#039;),
        sParameterName,
        i;
		for (i = 0; i &lt; sURLVariables.length; i++) {
        sParameterName = sURLVariables&#91;i&#93;.split(&#039;=&#039;);

        if (sParameterName&#91;0&#93; === sParam) {
            return sParameterName&#91;1&#93; === undefined ? true : sParameterName&#91;1&#93;;
        }
    }
};
&lt;!----------ham lay tham so duong dan trang web end------&gt;
var name = getUrlParameter(&#039;name&#039;);
var pass = getUrlParameter(&#039;pass&#039;);
</code></pre>
<br  />
<br  />
<br  />
<br  />
<br  />
&nbsp;
		</div>
	</div>
	<div id="footer" class="clearfix">
		<div id="url">
			<strong>URL của bản tin này: </strong><a href="http://phanmemthienha.com/news/huong-dan-phan-mem/tao-qr-code-voi-html5-javascript-119.html" title="Tạo QR Code với HTML5 - JavaScript">http://phanmemthienha.com/news/huong-dan-phan-mem/tao-qr-code-voi-html5-javascript-119.html</a>

		</div>
		<div class="clear"></div>
		<div class="copyright">
			&copy; PHAN MEM THIEN HA
		</div>
		<div id="contact">
			<a href="mailto:phamhuy842005@gmail.com">phamhuy842005@gmail.com</a>
		</div>
	</div>
</div>
        <div id="timeoutsess" class="chromeframe">
            Bạn đã không sử dụng Site, <a onclick="timeoutsesscancel();" href="http://phanmemthienha.com/#">Bấm vào đây để duy trì trạng thái đăng nhập</a>. Thời gian chờ: <span id="secField"> 60 </span> giây
        </div>
        <div id="openidResult" class="nv-alert" style="display:none"></div>
        <div id="openidBt" data-result="" data-redirect=""></div>
<script src="http://phanmemthienha.com/assets/js/jquery/jquery.min.js"></script>
<script>var nv_base_siteurl="/",nv_lang_data="vi",nv_lang_interface="vi",nv_name_variable="nv",nv_fc_variable="op",nv_lang_variable="language",nv_module_name="news",nv_func_name="savefile",nv_is_user=0, nv_my_ofs=7,nv_my_abbr="ICT",nv_cookie_prefix="nv4c_y8Y7D",nv_check_pass_mstime=1738000,nv_area_admin=0,nv_safemode=0,theme_responsive=1,nv_is_recaptcha=1,nv_recaptcha_sitekey="6LeSarIUAAAAAHRq6xkHwO6J0YYQOdMxgqKTXoL_",nv_recaptcha_type="image",nv_recaptcha_elements=[];</script>
<script src="http://phanmemthienha.com/assets/js/language/vi.js"></script>
<script src="http://phanmemthienha.com/assets/js/global.js"></script>
<script src="http://phanmemthienha.com/themes/default/js/news.js"></script>
<script src="http://phanmemthienha.com/themes/popovleather/js/main.js"></script>
<script src="http://phanmemthienha.com/themes/popovleather/js/bootstrap.min.js"></script>
</body>
</html>