ใช้ context.scale(x, y) ยืดหรือบีบวงกลมให้กลายเป็นวงรี ตัวอย่าง <!DOCTYPE HTML> <html> <head></head> <body> <canvas id=newCanvas width=450 height=300></canvas> <script> var c = document.getElementById(newCanvas); var context = c
ใช้ context.scale(x, y) ยืดหรือบีบวงกลมให้กลายเป็นวงรี ตัวอย่าง <!DOCTYPE HTML> <html> <head></head> <body> <canvas id=newCanvas width=450 height=300></canvas> <script> var c = document.getElementById(newCanvas); var context = c
ตั้งค่าคุณภาพการ resampling ด้วย ctx.imageSmoothingQuality = low|medium|high เทคนิคลดขนาดภาพแบบขั้นตอน (step-down scaling) เพื่อคุณภาพดีกว่า: // off-screen canvas var c = document.createElement(canvas), ocx = c.getContext(2d); c.width = img.width * 0.5; c.height = img.height * 0.5; ocx.drawImage(img
ใช้ <input type=file> ให้ผู้ใช้เลือกไฟล์ แล้วสร้าง Object URL ชี้ไปที่ไฟล์นั้น ขั้นตอน: change event: ยิงเมื่อผู้ใช้เลือกไฟล์ File object: เข้าถึงผ่าน input.files[0] Object URL: ใช้ URL.createObjectURL(file) สร้าง URL ชั่วคราว Set video.src: กำหนด Object URL ให้ video element รองรับรูปแบบ: M
เพื่อให้วิดีโอ MP4 เล่นขณะดาวน์โหลด (progressive streaming) ต้อง: เข้ารหัสวิดีโอให้ข้อมูล moov atom อยู่หน้า (fast start) - ใช้โปรแกรม mp4 FastStart หรือ HandBrake ตัวเลือก Web Optimized เว็บเซิร์ฟเวอร์ต้องไม่บีบอัดไฟล์ MP4 ซ้ำด้วย gzip/deflate (เพราะ MP4 บีบอัดแล้ว) ตรวจสอบ HTTP Response Headers ด
แท็ก <big> ทำให้ข้อความใหญ่กว่าปกติ แต่ ไม่รองรับใน HTML5 (deprecated) ตัวอย่าง (ไม่แนะนำ): <!DOCTYPE html> <html> <head> <title>HTML big Tag</title> </head> <body> <p>Questions and Answers: <big>Qries.com</big></p>
ใช้แอตทริบิวต์ spellcheck ตั้งค่า true หรือ false สำหรับ <input>, <textarea>, และองค์ประกอบที่ contenteditable หมายเหตุ: ไม่ทำงานกับ input type=password ตัวอย่าง <!DOCTYPE html> <html> <body> Subject : <input type=text name=sub spellcheck=true> <p>
แท็ก <bgsound> ใช้เล่นเพลงพื้นหลัง แต่ รองรับเฉพาะ Internet Explorer และ deprecated แล้ว ตัวอย่าง (IE only): <!DOCTYPE html> <html> <head> <title>HTML bgsound Tag</title> </head> <body> <bgsound src=/html/yourfile.mdi/> <p>
แท็ก <center> ใช้จัดข้อความกึ่งกลาง แต่ deprecated แล้ว ควรใช้ CSS text-align: center; แทน ตัวอย่าง (ไม่แนะนำ): <!DOCTYPE html> <html> <head> <title>HTML center Tag</title> </head> <body> <center>This text is centered</center>
ใช้แท็ก <caption> ภายใน <table> เพื่อเพิ่มคำอธิบายหัวข้อตาราง ตัวอย่าง <!DOCTYPE html> <html> <head> <style> table, th, td { border: 1px solid black; } </style> </head> <body> <h2>Cricketers</h2> <table
ใช้แท็ก <datalist> ร่วมกับ <input list=...> เพื่อให้รายการตัวเลือกแบบ autocomplete ตัวอย่าง <!DOCTYPE html> <html> <head> <title>HTML Datalist Tag</title> </head> <body> <input list=tutorials /> <datalist id=tutorials&g
ใช้แท็ก <dl> สำหรับ definition list <dt> สำหรับ term <dd> สำหรับ description ตัวอย่าง <!DOCTYPE html> <html> <head> <title>HTML dl Tag</title> </head> <body> <dl> <dt>Definition List</dt> <dd&g
ใช้แอตทริบิวต์ contenteditable ตั้งค่าเป็น true เพื่อให้ผู้ใช้แก้ไขเนื้อหาได้โดยตรงในเบราว์เซอร์ ตัวอย่าง <!DOCTYPE html> <html> <body> <p contenteditable=true>This content is editable. Try to edit it.</p> <p>This is a normal content. It wont edit.</p
ใน Definition List (<dl>) ใช้แท็ก <dt> สำหรับคำศัพท์ (term) และ <dd> สำหรับคำอธิบาย (description) ตัวอย่าง <!DOCTYPE html> <html> <head> <title>HTML dt Tag</title> </head> <body> <dl> <dt>Understanding Defini
ใช้แท็ก <section> เพื่อจับกลุ่มเนื้อหาที่เกี่ยวข้องกันเป็นส่วน (section) ในเอกสาร HTML5 ตัวอย่าง <!DOCTYPE html> <html> <head> <title>HTML Section Tag</title> </head> <body> <section> <h1>Java</h1> <h3>
AES (Advanced Encryption Standard) เป็นมาตรฐานการเข้ารหัสข้อมูล สามารถใช้ใน JavaScript ผ่านไลบรารี Forge ขั้นตอนการใช้งาน: ติดตั้ง NPM: npm install node-forge Minify เพื่อใช้ในโปรเจกต์: npm run minify ใช้ AES-CBC 128-bit encryption ciphers สร้าง key และ generate IV ตัวอย่าง: เข้ารหัสสตริงเพื่อเก็บ
ใช่ครับ JavaScript switch statement ใช้ Strict Equality (===) ในการเปรียบเทียบ ไม่ทำ type coercion ตัวอย่างทดสอบ: switch(1) { case 1: alert(Switch comparison: Not Strict.); break; case 1: alert(Switch comparison: Strict.); break; default: alert(Default); } ผลลัพธ์จะเป็น Swi
ใช้ window.history.forward() ร่วมกับ event handlers เพื่อป้องกันการย้อนกลับ หน้าปัจจุบัน (current page): <html> <head> <title>Disable Browser Back Button</title> <script src=https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js></script> &
ใช้ Unit.js - cross-platform open-source unit testing framework ตัวอย่าง var example = Welcome; test.string(example) .isEqualTo(Welcome); โครงสร้าง test suite: demo(Welcome, function() { demo1(Welcome to the website, function() { var example = Welcome; test.string(example) .isEqual
ทั้งสองวิธีทำงานต่างกันอย่างสิ้นเชิง: 1. Object.create() - สืบทอด prototype เท่านั้น: function SomeClass() { } SomeClass.prototype = Object.create(amitBaseClass.prototype); สร้าง prototype chain ใหม่ ไม่เรียก constructor ของ parent 2. new - เรียก constructor และสืบทอด instance ทั้งหมด: function Some
ใช้แท็ก <base> ใน <head> เพื่อกำหนด URL พื้นฐานสำหรับลิงก์ relative ทั้งหมดในหน้า ตัวอย่าง <!DOCTYPE html> <html> <head> <title>HTML base Tag</title> <base href=https://www.example.com /> </head> <body> Qries.com <img s