Enable JavaScript to use search. / 検索を使用するには JavaScript を有効にしてください。
Posts with #javascript
Mon, October 10, 2016
1 min read
[Atom.io] Format JavaScript source code with atom-beautify
Formatting JavaScript in Atom with the atom-beautify package.
read more →
Wed, August 19, 2015
2 min read
Recommended Atom Editor Packages Summary
Recommended Atom editor packages grouped by use case, plus an apm star snippet that installs them all at once.
Mon, March 30, 2015
[JavaScript] Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
Chrome refuses to $.getJSON from file:// — a memo on why, and how to serve JSON over http as a workaround.
Tue, April 7, 2020
How to Output Request and Response in Chrome Extensions
A sample Chrome DevTools extension that logs network request and response payloads via console.log.
Sat, December 29, 2012
[Chrome] Chrome extension 'jsoff' that can turn off JavaScript with one click
A quick pointer to 'jsoff', a Chrome extension for toggling JavaScript on and off with one click.
Tue, April 3, 2012
[JavaScript] Collection of CoffeeScript Beginner Articles
A link roundup of CoffeeScript beginner articles, commentary, sample code, and js2coffee.
Sun, September 1, 2013
[CoffeeScript] Eliminating that = this with @ and =>
A short link memo pointing to an article on avoiding that = this with CoffeeScript's @ and =>.
Sun, September 15, 2013
[CoffeeScript] Object Iterator is for of
In CoffeeScript, iterate over object keys with `for key of object` instead of `for in`.
Mon, October 3, 2011
[Facebook API] Function setAutoGrow() to Remove Scroll Bars in IFrame Tab Pages
Hide scroll bars on Facebook iframe tab pages by moving from setAutoResize to FB.Canvas.setAutoGrow().
Tue, October 4, 2011
[Facebook App] JavaScript SDK Must Always Be Used with https
Why you should always load the Facebook JavaScript SDK over https to avoid mixed-content issues, especially in IE.
Thu, May 3, 2018
[JavaScript] fast-safe-stringify is Convenient for Preventing TypeError: Converting circular structure to JSON
Use fast-safe-stringify to serialize circular references as [Circular] and avoid JSON.stringify TypeErrors.
Sun, October 27, 2013
[JavaScript] fastclick.js - Library to Speed Up Mobile Tap Events
A quick note on fastclick.js, a JavaScript library that speeds up mobile web tap events.
Thu, September 23, 2021
How to Fix Fastify 'Unsupported Media Type: application/x-www-form-urlencoded'
Fix Fastify's Unsupported Media Type: application/x-www-form-urlencoded by registering fastify-formbody.
Sun, January 8, 2012
7 min read
[JavaScript] Reading Google Analytics ga.js Source Code After Restoration
Restoring the compressed ga.js of Google Analytics with JsDecoder and reading its source.
12 min read
[JavaScript] Reading Google Analytics Urchin Module Source Code
Reading through the legacy Google Analytics Urchin Module (urchin.js) source code.
Sat, April 22, 2017
Web scraping with Google Apps Script ~ Checking if a page contains specific text
A Google Apps Script sample for checking whether a page contains a specific string via UrlFetchApp.
Thu, June 6, 2019
Sample Code to Redirect After Google Form Submission
Sample code that embeds a Google Form in an iframe and redirects to a custom URL after submission.
Thu, October 25, 2018
[Google Forms] JavaScript Sample Code to Get Radio Button, Checkbox, and Dropdown Options
JavaScript sample code to extract radio, checkbox, and dropdown options from a Google Form.
Thu, August 26, 2021
How to Redirect to Different Domains/URLs with Google Tag Manager + location.href
Injecting a JavaScript tag via GTM to redirect to another domain using location.href.
Wed, July 29, 2015
[Handlebars.js] Register custom helper methods with registerHelper
Registering and unregistering custom Handlebars.js helpers with registerHelper / unregisterHelper.
Fri, November 2, 2012
[IE6] Solution for Issues with javascript:void(0); and onclick Not Working
In IE6, href="javascript:void(0);" with onclick works once you add return false; at the end.
Tue, November 15, 2016
[JavaScript] Use onload event to execute processing after iframe loading completes
Use the iframe onload event to run JavaScript after loading, with a jQuery example to disable inner links.
Wed, October 12, 2011
[JavaScript] How to Use a href="" onclick
Avoiding the href="#" onclick anti-pattern in JavaScript, with good and bad examples.
Thu, December 26, 2019
[JavaScript] Array.includes vs Array.indexOf Performance Comparison
A performance comparison of Array.includes vs Array.indexOf on jsPerf and across Node.js versions.
Thu, February 13, 2014
[JavaScript] Get Maximum or Minimum Value from Array
A short snippet for getting the max and min from a JavaScript array with Math.max/min.apply.
Thu, July 1, 2021
JavaScript Bug When Using Array.sort() on Numeric String Formats
Why Array.sort() breaks on numeric string values in JavaScript, and two ways to fix it.
[JS] How to Check if jQuery is Loaded
A short sample using the typeof operator to check whether jQuery has been loaded.
Sat, August 25, 2012
[Javascript] How to Check if an Object is Empty
A short sample that uses Object.keys(obj).length to check whether an object is empty.
Thu, May 25, 2017
[JavaScript] 46 Ways to Convert Strings to Boolean
Several approaches for turning strings into Booleans in JavaScript — the !! idiom, strict comparison, and a toBoolean helper.
Tue, November 5, 2019
[JavaScript] Detecting Hyphens and Dashes with Regular Expressions Using unicode-regex + Dash_Punctuation
Detect the many kinds of hyphen and dash characters at once by combining unicode-regex with the Dash_Punctuation category.
Tue, August 4, 2015
[JavaScript] Performance comparison of Date.now vs new Date().getTime() vs +new Date
A jsPerf comparison of Date.now vs new Date().getTime() vs +new Date. Date.now was the fastest.
Mon, January 27, 2014
[JavaScript] document.write() Not Working
A link roundup of articles that explain why document.write() sometimes doesn't work.
Mon, July 17, 2017
[JavaScript/ES6] Promise Usage, Introduction, and Learning Resources Summary
Introductory articles, an e-book, a Workshopper module, and explainers for learning ES6 Promises.
Wed, July 19, 2017
[JavaScript/ES6] How to Use Single Quotes, Double Quotes, and Backticks
Using single quotes for string literals and backticks for template literals in ES6, based on MDN.
Sat, July 15, 2017
[JavaScript] Extract Only the Domain Part After @ from Email Address
A short sample that uses String.prototype.split() to pull the domain part out of an email address.
Tue, December 17, 2019
[JavaScript] How to Extract Only URL from CSS background-image
Basic and class-scoped samples for pulling the URL out of a CSS background-image value with regex.
Mon, January 20, 2014
[JavaScript] submit() Doesn't Work When There's name="submit" Element in Form
Why form.submit() breaks when an element has name set to submit, and the simple rename that fixes it.
Thu, October 31, 2019
JavaScript Function Currying Sample Code
Currying samples that let you call add(2)(3)(4).result(), written in both ES5 and ES6 styles.
Tue, October 22, 2019
Differences Between JavaScript Functions and Methods
The difference between JavaScript functions and methods, framed around MDN, CodeZine, and how this is bound.
Thu, February 9, 2017
[JavaScript] How to Get the Number of Decimal Places
A getDecimalPlace helper that uses toString().split('.') to count decimal places in JavaScript.
Sat, August 18, 2012
[Javascript] HTML Escaping htmlspecialchars
Sample JavaScript code that mirrors PHP's htmlspecialchars for escaping HTML-special characters.
Thu, May 14, 2020
JavaScript Sample Code to Execute Only in Internet Explorer 11
Sample JavaScript that shows an alert() only in Internet Explorer 11, with a public demo on GitHub.
Sun, October 16, 2011
How to Change Form Action with JavaScript and jQuery
Minimal sample code for changing a form's action attribute with vanilla JavaScript and jQuery.
Tue, January 15, 2013
[JavaScript][jQuery] Checking for the existence of DOM elements
Six ways to check DOM element existence in JavaScript and jQuery, ranked by execution speed.
[JavaScript][jQuery] How to Get DOM Elements
How to get a raw DOM Element from a jQuery object with .get(0), alongside the vanilla getElementById equivalent.
Tue, July 24, 2018
JavaScript Integer Maximum and Minimum Values Are Defined by Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER
JavaScript exposes its max and min safe integers as Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER.
Thu, September 6, 2012
[JavaScript] How to Simply Measure Execution Time in Milliseconds
A quick JavaScript snippet to measure execution time in ms using Date.getTime().
Thu, October 17, 2019
[JavaScript] Median Calculation Sample Code and Math.js Usage Examples
Compute the median in JavaScript with Math.js's math.median, or hand-written ES5 / ES6 functions.
Fri, July 21, 2017
4 min read
[JavaScript] Reference Information for Understanding Memory Management (Japanese & English)
MDN's Japanese and English Memory Management pages as reference material for learning JavaScript GC.
Thu, December 15, 2016
Promise reference articles summary [JavaScript/ECMAScript6]
A personal reading list of reference articles for learning ES2015 Promises in JavaScript and Node.js.
Tue, May 4, 2021
How to Generate n-Character Random Alphanumeric Strings in JavaScript
Two ways to generate n-character random alphanumeric strings in JavaScript: Math.random and crypto.getRandomValues.
Mon, October 6, 2014
[JavaScript] Method for merge recursive
A short note on using lodash.merge for recursive object merges in JavaScript.
Fri, August 4, 2017
Using Regular Expressions to Extract Strings After a Specific String [JavaScript Edition]
Sample JavaScript regex code for extracting the string that follows a specific label such as `Email address:`.
Tue, December 20, 2016
[JavaScript] Regular Expression and Snippet to Replace Line Break Characters \r\n \r \n with Spaces
A JavaScript regex snippet that replaces \r\n, \r, and \n line breaks with a single space.
Sun, February 5, 2017
[JavaScript] Remove All Elements with Specified ID or Class Name
Pure JavaScript functions to remove DOM elements by id or class name, no jQuery required.
Tue, September 17, 2019
[JavaScript] How to Fix the Problem Where removeEventListener Cannot Remove Events
Why removeEventListener silently fails when the listener is redefined, and how to fix it by lifting the listener out.
Thu, June 13, 2019
How to Replace Control Characters in JavaScript
Sample code for replacing control characters in JavaScript with String.prototype.replace and a regular expression.
Tue, December 26, 2017
[JavaScript] Rewrite a href URLs based on the currently accessed domain
JavaScript sample that inspects document.domain and rewrites an a href URL only on the test environment.
Thu, October 26, 2017
[JavaScript] setTimeout(function(){}, 1) Can Sometimes Result in the Same Time Even When Specifying 1 Millisecond
Even with a 1 ms setTimeout, Date.now() inside the callback can match the caller's value — reproduced in the Node.js REPL.
Thu, September 26, 2019
[JavaScript] Sample Code for Timezone String Validation with moment.tz.zone
Validate timezone strings in JavaScript with Moment Timezone's moment.tz.zone in just a few lines.
Thu, November 7, 2019
[JavaScript] Use unicode-substring for Extracting Parts of Strings Containing Unicode
Why substring breaks surrogate pairs — and how the unicode-substring package slices Unicode strings safely.
Thu, March 8, 2018
[JavaScript] Quick solution for URI malformed / malformed URI sequence errors
A quick try...catch workaround for the URIError raised by decodeURIComponent on invalid input.
Sat, January 25, 2014
[JavaScript] Ajax GET with XMLHttpRequest
Sample code for an ajax GET request using the raw XMLHttpRequest API, with an ActiveXObject fallback for IE.
Thu, January 9, 2014
[jQuery] How to Disable Caching for $.ajax GET
Stop jQuery $.ajax GET from being cached in IE by setting cache: false per request or globally via $.ajaxSetup.
Fri, September 27, 2013
[jQuery] jQuery.ajax(options), $.ajax Memo
A sample-code memo for the options and success / error / complete callback arguments of jQuery's $.ajax.
Thu, September 19, 2013
[jQuery] How to Get Checked Checkbox Values and Store Them in an Array
A memo on collecting checked checkbox values into an array using jQuery's :checked selector and each().
Thu, August 8, 2013
[jQuery] How to Clear, Reset, and Empty Form Values
A jQuery snippet for clearing form values across a whole form or within a specific area such as a modal.
Mon, March 5, 2012
[jQuery] ClockPick Library for Easy Time Input is Convenient!
Setup notes for the jQuery time-input library ClockPick, configured for 24-hour format with 5-minute intervals.
Wed, September 20, 2017
jquery-cookie is No Longer Maintained and Sometimes Doesn't Work, So Use js-cookie
jquery-cookie is no longer maintained and its authors point users to the successor library, js-cookie.
Sat, March 8, 2014
Changing the time display format of jQuery Countdown
A snippet memo for customizing jQuery Countdown's display with its separator and label_* options.
Sun, March 9, 2014
Snippet to display only days with jQuery Countdown
A jQuery Countdown snippet using compact and format: 'D' to show only the remaining days.
Thu, June 12, 2014
[jQuery] Integers can be rounded with .data() so use .attr() to retrieve them
Older jQuery's .data() rounds long integer data-* values, so use .attr() to keep them intact as strings.
Sun, December 9, 2012
[JavaScript] How to Fix Sidebar Parts with jQuery When Scrolling
Link collection of reference articles for fixing a sidebar in place while scrolling with JavaScript or jQuery.
Wed, November 23, 2011
[jQuery] Sample Code for Countdown Timers Commonly Seen on Groupon-Style Sites
Sample code for a Groupon-style countdown timer built with plain jQuery and setTimeout — no plugin needed.
Tue, December 10, 2013
[jQuery] Plugin 'hcSticky' for Fixing Specific Elements While Scrolling
The jQuery plugin hcSticky pins an element in place while scrolling — just call hcSticky() on the target.
Mon, December 9, 2013
[jQuery] Triggering onChange Events with Minimalect
A snippet for firing the underlying select's change event from Minimalect's onchange option.
Wed, October 16, 2013
[jQuery] How to Reflect Value Changes in Minimalect
With Minimalect, chain .change() after .val() so the display reflects the new value.
Tue, December 3, 2013
[jQuery] Differences Between mouseover/mouseout and mouseenter/mouseleave
A note on how mouseover/mouseout and mouseenter/mouseleave differ when the cursor crosses inner DOM elements.
Sun, November 27, 2011
[jQuery] How to Open Links to External Sites in a New Window
Sample code that opens links with a given class in a separate sized window using jQuery and window.open.
Mon, February 11, 2013
[jQuery] Prevent Double-clicking and Consecutive Clicks on Forms and Links
A memo of reference links for preventing double-clicking and consecutive clicks on forms and links with jQuery.
Tue, September 18, 2012
[jQuery] Using Proxy Pattern to Override Methods
A memo on overriding window.alert with the Proxy Pattern in jQuery.
Tue, April 28, 2020
Sample Code for Internal Page Navigation with <a href="id"> Links Using jQuery Scrollify
Sample code for making <a href="#id"> links navigate within a page using jQuery Scrollify.
Thu, April 16, 2020
jQuery Scrollify Basic Setup Sample Code
Sample code based on jQuery Scrollify's Basic setup, with notes on the setHeights and overflowScroll options.
Thu, April 2, 2020
How to Use jQuery Scrollify - Issues & Solutions
Issues I ran into while using jQuery Scrollify and how I solved them.
Sat, December 14, 2013
[jQuery] Solution When slideDown() Animation Doesn't Work
How to fix jQuery slideDown() not animating on nested divs, using show().slideDown().
Thu, February 14, 2013
[jQuery] Split Date-Time Input Forms into Two and Use Datepicker and Timepicker
Split date-time inputs into two fields and use Datepicker plus Timepicker separately.
Thu, April 23, 2020
CSS3 Text Animations with jQuery textillate.js
Sample code for driving CSS3 text animations with jQuery textillate.js.
Sat, April 25, 2020
Text Wrapping Sample Code with jQuery textillate.js
Sample code verifying text wrapping behavior with jQuery textillate.js.
Sat, May 26, 2012
[jQuery] Usage and Reference Articles for "ThickBox" - Easy Dialog Display
Reference links for learning how to display dialogs easily with jQuery ThickBox.
Tue, August 23, 2011
How to Close a jQuery UI Dialog From Inside an Iframe
How to close a jQuery UI Dialog from inside an iframe via window.parent.
Mon, July 22, 2013
JavaScript Sample Code for URL Scheme Launch on Android and iPhone with Store Redirect if App Not Downloaded
JS sample that launches an app via URL scheme, redirecting to the app store on failure.
Fri, April 11, 2014
[JavaScript] js2coffee Converts arguments to arguments_
Js2coffee silently renamed arguments to arguments_ and caused a runtime error.
Sat, December 22, 2012
JsDoc Toolkit Introduction
Intro notes on JsDoc Toolkit — reference sites, Homebrew install, and templates.
Sun, January 11, 2015
[JavaScript] jsdom memory leak
Fixed an out of memory error in a jsdom scraper by calling window.close().
Sun, September 28, 2014
I Contributed to the Official Site for Kaze to Rock Imonikai 2014 BASEBALL
Kaze to Rock Imonikai 2014 BASEBALL ran on September 27 and 28, 2014. Its official site featured a countdown styled after a ballpark scoreboard, and I implemented the days-remaining logic in JavaScript. A small scope, but one worth recording.
Sun, February 5, 2012
[JavaScript] Installing SpiderMonkey on Mac with Homebrew
Installing SpiderMonkey with Homebrew so you can run JavaScript from the console via the js command.
Sat, March 25, 2017
[Mocha] Execution order of before, beforeEach, after, afterEach
The execution order of Mocha's before, beforeEach, afterEach, and after hooks with sample code.
Fri, November 25, 2016
3 min read
Reusing variables between different versions of Moment.js and Moment Timezone resulted in spectacular bugs
Mixing Moment.js and Moment Timezone versions broke date handling due to how the _d property is treated.
Fri, April 24, 2015
[Moment Timezone] How to Use moment.tz
The two Moment Timezone interfaces — moment.tz(..., String) and moment().tz(String) — with code samples.
Tue, November 8, 2016
moment-timezone old version caused date processing bugs during daylight saving time switch
An old moment-timezone bugged out at the DST switch — upgrading fixed it, and here's why tz updates matter.
Mon, March 3, 2014
[JavaScript] Change Date Type Timezone to JST with moment.js
A short moment.js snippet for converting a Date value to the Asia/Tokyo timezone.
Mon, September 30, 2013
[JavaScript] moment.js - A Library for Easy Date and Time Handling
A short bookmark memo about moment.js, a handy JavaScript date/time library.
Sun, March 12, 2017
[MongoDB] Query to Get Documents with nth Decimal Places and Update with mth Decimal Place Values
Use $where and `toFixed(2)` to round prices with 3+ decimal places down to two.
Sat, July 29, 2017
Created .jshintrc Specialized for MongoDB Queries
A MongoDB-specific .jshintrc that registers mongo shell methods as globals to silence JSHint noise.
Sat, December 14, 2019
How to Measure Total Execution Time of MongoDB Queries
Measure total execution time of a multi-line MongoDB query block with a simple new Date() diff.
Tue, February 26, 2019
[MongoDB] How to resolve SyntaxError: Unexpected end of input, Unexpected token }
When a regex literal breaks the MongoDB shell with SyntaxError, use the RegExp constructor instead.
Wed, October 19, 2011
[PHP][JavaScript] Encoding and Character Garbling Issues with urlencode and encodeURI
Skip PHP-side urlencode and rely on JavaScript's encodeURI to avoid IE mojibake.
Sun, January 15, 2012
[Resources] 'Let's Read the World's JavaScript @ 2012'
A slide deck that summarizes the JavaScript landscape and information-gathering methods circa 2012.
Sat, December 7, 2019
ReconnectingWebSocket - JavaScript Library for Handling WebSocket Auto-Reconnection Elegantly
Side-by-side sample code for WebSocket auto-reconnection using the raw API vs the ReconnectingWebSocket library.
Thu, June 1, 2017
Using Regular Expressions to Append Specific Strings After Image URL Extensions .jpeg .jpg .png
A JavaScript regex snippet that appends .webp after .jpeg / .jpg / .png in image URLs, query parameters included.
Thu, December 12, 2019
How to Prevent Sending JavaScript Errors from Specific Browsers with Sentry raven-js
Sample code that filters out errors from unsupported browsers (like pre-IE11) using Sentry raven-js's shouldSendCallback.
Wed, December 23, 2015
[jQuery] Understanding slick.js carousel library's lazyLoad
Using slick.js's lazyLoad option and understanding the difference between ondemand and progressive modes.
Thu, March 2, 2023
Syncing Address Information from SmartHR API to Google Sheets with Google Apps Script
A Google Apps Script sample that syncs employee address data from the SmartHR API into a Google Sheet.
Sat, August 31, 2019
Modern Mobile-responsive JavaScript slider library Swiper
How I modified Swiper's sample code to load from CDN so the demos run as a standalone file.
Wed, December 2, 2015
[Twitter] Capturing custom events from tweet button and executing something when clicked
A JavaScript snippet that binds a callback to the Twitter tweet button click event via twttr.events.bind.