Tips & Tutorials – Javascript

Javascript Fetch With HTTP Basic Auth (Simple Example)

Welcome to a tutorial and example on how to do a Javascript Fetch request with HTTP basic auth. To perform Fetch with HTTP basic auth, simply include the authorization headers in the request. var credentials = btoa(“USER:PASSWORD”); var auth = { “Authorization” : `Basic ${credentials}` }; fetch(“http://site.com/protected/”, { headers : auth }); That covers the …

Javascript Fetch With HTTP Basic Auth (Simple Example) Read More »

How To Add Leading & Trailing Zeroes To Numbers In Javascript

Welcome to a short tutorial on how to add leading and trailing zeroes to numbers in Javascript. So you have some numbers that require padding of zeroes? The easy way to add leading or trailing zeroes in Javascript is to: Concatenate the number with a string of zeroes. var num = “000” + 123; var …

How To Add Leading & Trailing Zeroes To Numbers In Javascript Read More »

Download File With Javascript Fetch (Simple Example)

Welcome to a tutorial and example of how to download a file using Javascript Fetch. Want to initiate a file download using Javascript Fetch? Yes, it is possible. To download a file using Javascript fetch, return the result as a blob, and create a download link to the blob object. fetch(“URL”) .then((res) => { return …

Download File With Javascript Fetch (Simple Example) Read More »

Toggle Fullscreen Mode With Javascript (Very Simple Examples)

Welcome to a quick tutorial and examples of how to toggle fullscreen mode with Javascript. Yes, the old grandmother’s age of the Internet is over now. Modern web browsers can be switched to full-screen mode in Javascript easily. To enter fullscreen mode for the entire page  – document.documentElement.requestFullscreen() To enter fullscreen mode for a specific …

Toggle Fullscreen Mode With Javascript (Very Simple Examples) Read More »

5 Ways to Pass Variables Between Pages In Javascript

Welcome to a tutorial on how to pass variables between pages in Javascript. Need to pass some data between different pages? An easy way to pass variables between pages is to use a query string: On the first page: var para = new URLSearchParams(); para.append(“KEY”, “VALUE”); location.href = “HTTP://SITE.COM/PAGE.HTML?” + para.toString(); On the second page: …

5 Ways to Pass Variables Between Pages In Javascript Read More »