Skip to Content
Menu

get()

Get (or check) a specific query string.

JavaScript February 7, 2021

Usage

JavaScript
nebula.get(parameter, url)

Parameters

parameter
(Optional) (String) The query parameter to look for
Default: Full query string

url
(Optional) (String) The URL to parse for query parameters
Default: location.search

Parameter Notes

If a parameter is not passed, it returns all query strings exactly like getQueryStrings().

Request or provide clarification »

Examples

JavaScript
if ( nebula.get('foo') === 'bar' ){
    //Do something if ?foo=bar is in the URL
}
JavaScript
if ( nebula.get('foo') ){
    //Do something if ?foo or ?foo=anything is in the URL
}

Demo


Visit this page with the query string ?hello (or ?hello=whatever) and open the JavaScript console to see it.

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /assets/js/modules/utilities.js on line 199.

    No Hooks

    This function does not have any filters or actions available. Request one?
    JavaScript
    nebula.get = function(parameter = false, url = location.search){
        let queryParameters = new URLSearchParams(url);
    
        let queries = [];
        queryParameters.forEach(function(value, key){
            queries[key] = value;
        });
    
        if ( !parameter ){
            return queries;
        }
    
        return queries[parameter] || false;
    };
    

    Override

    To override or disable this JavaScript function, simply redeclare it with the exact same function name.

    JavaScript
    nebula.get = function(parameter, url){
        //Write your own code here, leave it blank, or return false.
    }