UrlUtil

This page details the UrlUtil endpoints and the actions they support. It covers key functions, parameters, and sample code for easy implementation.

  • URL: /jw/js/json/util.js
  • Auto included in all userview pages.
  • Convenient method to deal with URL.

 

constructUrlQueryString(params)

Used to generate a query string based on a parameters object.

  • Parameters:
    • params - an object contains all parameters as attribute names and their values in the array.
  • Sample code: 
var params = {
    "name" : ["joget"],
    "email" : ["info@joget.org", "test@joget.org"]
};
var queryString = UrlUtil.constructUrlQueryString(params);
console.log(queryString); // name=joget&email=info%40joget%2Eorg&email=test%40joget%2Eorg

 

encodeUrlParam(url)

Used to encode the URL parameters in a URL.

  • Parameters:
    • url - URL with parameters to be encoded. Note that it uses "&" and "=" as separators.
  • Sample code: 
var url = "http://localhost/jw/test?name=joget&email=info@jogte.org&email=test@joget.org";
  
var encodedUrl = UrlUtil.encodeUrlParam(url);
console.log(encodedUrl); // http://localhost/jw/test?name=joget&email=info%40joget%2Eorg&email=test%40joget%2Eorg

 

getUrlParams(url)

Used to get an object containing all parameters as attribute name and its value in a URL.

  • Parameters:
    • url - URL to be parsed to retrieve all parameters and their value in the array.
  • Sample code: 
var url = "http://localhost/jw/test?name=joget&email=info@jogte.org&email=test@joget.org";
  
var params = UrlUtil.getUrlParams(url);
console.log(params); // {"name" : ["joget"], "email" : ["info@joget.org", "test@joget.org"]}

 

mergeRequestQueryString(queryString1, queryString2)

Used to merge 2 URL query parameter strings into one query string.

  • Parameters:
    • queryString1 - first query parameters string
    • queryString2 - second query parameters string. If a parameter exists in both query strings, the value in the second query string will override the first one.
  • Sample code: 
var q1 = "name=joget&email=info@jogte.org&email=test@joget.org";
var q2 = "name=joget team&phone=012345678";
  
var queryString = UrlUtil.mergeRequestQueryString(q1, q2);
console.log(queryString); // name=joget%20team&email=info%40joget%2Eorg&email=test%40joget%2Eorg&phone=012345678

 

Created by Damian Last modified by Aadrian on Dec 13, 2024