Within the code page use this script
var urlParams = new URLSearchParams(window.location.search);
urlParams.get("a"); // "dbpage"
urlParams.get("pagename"); // "InvoicePDF.html"
urlParams.get("rid"); // value of [Record ID#]
You used to have to use a library to parse the query string but now we have URLSearchParams native in JavaScript.