Copying Text to the Clipboard with JavaScript

In the past, using JavaScript to copy and paste text through the clipboard was very cumbersome. While developing NTUST.ME, a short URL service for National Taiwan University of Science and Technology, I wanted to make it easy for people to copy the shortened URLs, so I looked into the clipboard API in JavaScript. I found that newer browsers have an execCommand function that supports many handy text operations, such as copy and select all. Let me introduce it to you! ...

December 10, 2016 · 2 min

Enable Cross-Origin Resource Sharing (CORS) for Phaser.js

When you load resources and assets from a different domain in Phaser JS, the browser’s same-origin policy blocks them, and you get a pile of error messages, such as: XMLHttpRequest cannot load http://s.ntustcoding.club/scroll-game-workshop/map.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://s.codepen.io' is therefore not allowed access. Actually, Phaser itself supports Cross-Origin Resource Sharing (CORS). You can solve this with one simple line, as long as the web hosting you use also supports CORS....

December 2, 2016 · 2 min

【jQuery】Lazyload - Delayed Image Loading

Photography websites often have a lot of images. When visitors browse these sites, it takes quite a while to load because so many photos have to be loaded. This has a big impact on the website’s host traffic, and it also increases the CPU time on the visitor’s side a lot. Here I want to introduce Lazyload, a jQuery plugin that delays image loading. In other words, when you enter a website, it doesn’t load all the images at once. It only loads some of them, and as you scroll the browser, it loads “the images in the section you are looking at,” so the page loads faster. ...

April 27, 2011 · 1 min

[JavaScript] encodeURIComponent: A Function for Encoding URLs

When you use JavaScript to make GET requests, you’ll often run into the fact that JavaScript requires the URL to be encoded. For functions that need an encoded URL, you can use encodeURIComponent to encode it. ...

July 22, 2009 · 1 min