Created
October 17, 2021 16:01
-
-
Save arturmkrtchyan/8b46b512571c1e60a386994ffe6ebdbc to your computer and use it in GitHub Desktop.
get_record_id.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
document.addEventListener("DOMContentLoaded", function() { | |
const recordId = getUrlParam('recordId'); | |
console.log(recordId); | |
function getUrlParam(name) { | |
const url = new URL(window.location.href); | |
let param; | |
for (var key of url.searchParams.keys()) { | |
if (key.toLowerCase() === name.toLowerCase()) { | |
param = url.searchParams.get(name); | |
break; | |
} | |
} | |
if (!param && name.toLowerCase() === 'recordid') { | |
param = getRecordIdFromPath(); | |
} | |
return param; | |
} | |
function getRecordIdFromPath() { | |
let pathName = window.location.pathname; | |
if (pathName.indexOf('/r/rec') !== -1) { | |
pathName = pathName.substr(pathName.indexOf('/r/rec') + 3); | |
if (pathName.indexOf("/") !== -1) { | |
pathName = pathName(0, pathName.indexOf('/')) | |
} | |
return pathName; | |
} | |
return undefined; | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment