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”Redirecting to www or non-www using Apache htaccess
Redirecting the domain to a www or non-www URL can help with URL canonicalization by search engines – the process by which a search engine selects which version of your site’s URL to display in search results.
Continue reading “Redirecting to www or non-www using Apache htaccess”macOS – find, start, stop, and restart the Apache web server
Trying to find out if the Apache server is running on macOS? How to find it? And once you find it, why are there several methods to start, stop and restart it? You may feel lost. Let’s sort this out.
Continue reading “macOS – find, start, stop, and restart the Apache web server”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.
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.
Simple steps to convert a webpage into a PDF file
To save a webpage without html tags as a PDF (Portable Document Format), you can follow different methods depending on the browser or device you are using.
You don’t need to implement any JavaScript code to achieve that, but the page has to be printer-ready (implemented styles for CSS media type print).
Continue reading “Simple steps to convert a webpage into a PDF file”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.