JavaScript Copy to Clipboard Button (Tested Code)
A copy to clipboard button in plain JavaScript: copy text from a div or input on click, show Copied!, fall back on plain HTTP, and add Copy buttons to code blocks.
Notes
Security notes, SOC lab write-ups and tested code by Mahir Faysal, a SOC Level 1 cybersecurity learner in Bangladesh, plus notes from my Next.js and Gemini projects. Sample posts are marked and drafts stay in the admin area.
A copy to clipboard button in plain JavaScript: copy text from a div or input on click, show Copied!, fall back on plain HTTP, and add Copy buttons to code blocks.
Two UK postcode regex patterns for JavaScript tested on 14 inputs, a function that tidies 'sw1a1aa' into 'SW1A 1AA', and a form that uses it.
Turn 1234.5 into £1,234.50 with Intl.NumberFormat: commas, no symbol, whole pounds, accounting negatives, other currencies, and why to add money in pence.
Format any JavaScript date as dd/mm/yyyy with a five-line function or toLocaleDateString('en-GB'), plus time zones, parsing UK dates and the month-0 trap.
Count and add working days in JavaScript with UTC dates, skip weekends and UK bank holidays from gov.uk's JSON, and avoid the clocks-change bug.
Work out a First, 2:1 or 2:2 from module marks: credit-weighted averages, 30:70 or 1:2 year weightings, rounding at 69.5 and the mark you need.
0%