Skip to content

Instantly share code, notes, and snippets.

@arturmkrtchyan
Created December 21, 2021 22:29
Show Gist options
  • Save arturmkrtchyan/e2f5c6e2ba0ebd6951b632b34cf4fbb3 to your computer and use it in GitHub Desktop.
Save arturmkrtchyan/e2f5c6e2ba0ebd6951b632b34cf4fbb3 to your computer and use it in GitHub Desktop.

Revisions

  1. arturmkrtchyan created this gist Dec 21, 2021.
    43 changes: 43 additions & 0 deletions dynamic_record_id_placement.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    <script>
    document.addEventListener("DOMContentLoaded", function () {
    let recordId = getUrlParam('recordId');
    var exitCondition = setInterval(function() {
    $('a').each(function() {
    if($(this).attr('href') && $(this).attr('href').endsWith('{URL_PARAM:recordId}')) {
    const url = $(this).attr('href').replace('{URL_PARAM:recordId}', recordId);
    $(this).attr('href', url);
    }
    });
    }, 600);



    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>