To create accessible truncated text, it’s crucial to consider both the visual presentation and accessibility implications. Here are key points and techniques to achieve this.
Continue reading “Truncating text and making it accessible”Alternative text for CSS generated content
The majority of content on the web is conveyed using HTML. However, CSS may also be used to insert content into a web page.
But how do we actually make the CSS content
property accessible for screen readers?
Resolving the script tag type attribute hash prepending issue with Cloudflare
If your script
HTML tag has the type
attribute prepended with a hash, like <script type="ea10e272b0a1989fb2f3aa4e-text/javascript">...</script>
and you’re using Cloudflare services, then the root cause is the Cloudflare Rocket Loader, a feature of Cloudflare that optimizes the loading of JavaScript resources on your web pages.
Rocket Loader modifies the type
attribute of script
tags for website loading optimization by deferring the loading of JavaScript until after rendering. This modification can sometimes cause issues with HTML validation and Content Security Policy (CSP) headers.
Cloudflare Rocket Loader adds an argument “type” into the script
tag and causing issues with the W3C validator due to the “subtype missing” error.
Get days between two dates in JavaScript
To get the number of days between two given dates, you can do that by converting them to UTC timestamps and then computing the difference in days based on the millisecond difference.
Continue reading “Get days between two dates in JavaScript”Get and capitalize the first letter of a string in JavaScript
To covert a first letter in the string to upper case we need to use toLocaleUpperCase
and taking the surrogate pairs into account.
Best practices for optimizing SVG code
To optimize SVG code, you can follow several best practices and use various tools. Here are some recommended best practices for optimizing SVG code.
Continue reading “Best practices for optimizing SVG code”Convert SVG to image in browser: PNG, JPEG, WebP
To convert SVG to PNG, JPG, or WebP , you can use the DOM API to create an object URL from the SVG code, load it into an image element, and then write that image to a Canvas. Finally, you can use the toDataURL()
method to convert the Canvas to a base64 encoded PNG image.
How to find the highest z-index on a page using JavaScript
To find the highest z-index
value on a page using JavaScript, you can loop through all the elements on the page and check their z-index
values. The element with the highest z-index
value will be the one that appears on top of all other elements.
Add a badge to the browser tab favicon using JavaScript
Adding a badge to the favicon using JavaScript can be done by updating the image specified by the <link />
element with a new icon image.
This method involves JavaScript and creating an in-memory canvas
element, applying the favicon image, drawing the badge shape and text on top, and then updating the <link />
element’s href
attribute with the final composite of the canvas element’s image data as a Base64 encoded string.
Check if a string is valid HTML using JavaScript
Validating if a string is valid HTML can be done using DOMParser API and its method parseFromString
.
The DOMParser API interface allows you to parse XML or HTML source code from a string and convert it into a DOM Document. It is used to convert a string of XML or HTML into a structured DOM object that can be easily manipulated using JavaScript.
Continue reading “Check if a string is valid HTML using JavaScript”