Today I Learned - Rocky Kev

TIL the JS Library Current Device

POSTED ON:

TAGS:

I worked on a project where android phones and iOS Tablets were giving me WILDLY different results. WebKit Safari bug;

This libary does the following:

  1. It injects the OS, device type and position into the html element.

<html class="ios tablet landscape">

So you can do hacky things like:

.ios body {
background-color: red;
}
  1. You also can fire specific JS code based on that as well.

body.addEventListener("click", () => {

if (device.landscape()) {
console.log("I'm in landscape!")
}

});

You really shouldn't be targetting this level of specificity.
But then again, WebKit (Safari iOS) is a pain in the ass.

Reference
https://matthewhudson.github.io/current-device/


Related TILs

Tagged:

TIL why you should always use textContent

Today I learned the difference between 'Node.textContent'. It handles all elements, even hidden ones. It also prevents XSS attacks since it strips tags.

TIL prepend

When you're creating new elements in Javascript, you want to attach the new element to something that exists in the DOM already. You do that with append, and prepend.

TIL the simulating a Pipe function

It’s a pipe function that allows you to chain multiple operations together by taking a series of functions as arguments and applying them in a specific order to the input.