• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Archives for JavaScript

JavaScript

How to Disable beforeunload Event Listeners

Last updated on August 4, 2022 by Sal Ferrarello

I was doing some troubleshooting and wanted to disable the “beforeunload” event listeners on a page. This is how I accomplished it with the Chrome browser.

Filed Under: Computing, Dev Tips, Programming, Solution Tagged With: Chrome, JavaScript

WordPress Gutenberg Trigger Autosave

Last updated on April 25, 2022 by Sal Ferrarello

Recently, I was documenting the steps to reproduce a certain bug and the bug required the presence of an autosave (along with the “There is an autosave of this post that is more recent than the version below.” message). Rather than wait for an autosave to occur naturally, I wanted to speed things up and manually trigger one. This is the command I use to do that.

Filed Under: Dev Tips, Solution Tagged With: Gutenberg, JavaScript, WordPress

JavaScript Unix Timestamp from String in Time Zone

Last updated on February 27, 2022 by Sal Ferrarello

Given a string like “2022-01-01 13:00:00”, which represents a time in the “Europe/Paris” timezone, how can we get the corresponding Unix Timestamp in JavaScript? This problem is sufficiently complex that in my opinion leveraging a third-party library is the best solution.

Filed Under: Dev Tips, Programming, Solution Tagged With: DateTime, JavaScript, time zone

WordPress Gutenberg Notice in JavaScript

Last updated on February 20, 2022 by Sal Ferrarello

You can display four types of notices in the WordPress Block Editor (a.k.a. Gutenberg) using JavaScript: error, warning, info, and success. This blog post contains an example of each.

Filed Under: Dev Tips, Programming Tagged With: Gutenberg, JavaScript, WordPress

Display Keyboard Shortcut in WordPress Gutenberg

Last updated on October 15, 2021 by Sal Ferrarello

In Gutenberg (a.k.a. the WordPress Block Editor), keyboard shortcuts are displayed differently on Apple devices and other devices, e.g. ^H on an Apple device and Ctrl+H on other devices. This is accomplished with wp.keycodes.displayShortcut.

Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Programming Tagged With: Gutenberg, JavaScript, WordPress

JavaScript Or (||) Versus Nullish Coalescing Operator (??)

Last updated on November 3, 2022 by Sal Ferrarello

The “or” (||) operator and the “nullish coalescing operator” (??) can often be used in similar ways when reading a property from an object that may or may not exist. When dealing with strings you’re typically better off using “or” (||) and for numbers you’re typically better off using the “nullish coalescing operator” (??).

Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Programming, Recommendations Tagged With: JavaScript

Promise and Async / Await

Last updated on April 30, 2021 by Sal Ferrarello

Making fetch calls with Promises vs async/await.

Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Draft, Programming Tagged With: JavaScript, JS async / await, JS Promise

Join Strings with Commas and “And” in JavaScript

Last updated on July 16, 2020 by Sal Ferrarello

In English the rules we use for joining a list of items involves more work than a standard join in JavaScript. Here is JavaScript code to join an array of elements with commas and an “and”.

Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Programming, Solution Tagged With: JavaScript

JavaScript get Date in YYYYMMDD Format

Last updated on June 15, 2020 by Sal Ferrarello

Recently, I was working in JavaScript and I need to transform a date into the format YYYYMMDD, this is how I did it.

Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Computing, Dev Tips, Draft, Programming, Solution Tagged With: DateTime, JavaScript

Add Gutenberg JavaScript Filter

Last updated on May 18, 2020 by Sal Ferrarello

WordPress PHP filters allow you make a value modifiable from outside of your code. With the WordPress Block Editor (a.k.a. Gutenberg), you can now do the same thing in JavaScript.

Filed Under: Dev Tips, Programming, Solution Tagged With: Gutenberg, JavaScript, WordPress, WordPress Filter

  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Next Page»

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in