Skip to content

Instantly share code, notes, and snippets.

@adamdehaven
Created October 30, 2020 19:35

Revisions

  1. adamdehaven created this gist Oct 30, 2020.
    17 changes: 17 additions & 0 deletions getUrlParams.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    /**
    * Return the value of a URL parameter
    * @param url String
    * @param key String
    */
    const getUrlParam = (url, key) => {
    const results = new RegExp('[?&]' + key + '=([^&#]*)').exec(url)
    return results ? decodeURI(results[1]) : null
    };

    // Get the URL
    const url = window.location.href

    // Usage
    if (getUrlParam(url, 'success')) {
    // Do something
    }