mirror of
https://github.com/yogeshojha/rengine.git
synced 2026-09-20 08:47:43 +02:00
30 lines
1.0 KiB
JavaScript
30 lines
1.0 KiB
JavaScript
// seperate hostname and url
|
|
// Referenced from https://stackoverflow.com/questions/736513/how-do-i-parse-a-url-into-hostname-and-path-in-javascript
|
|
function getParsedURL(url) {
|
|
var parser = new URL(url);
|
|
return parser.pathname+parser.search;
|
|
};
|
|
|
|
function getCookie(name) {
|
|
var cookieValue = null;
|
|
if (document.cookie && document.cookie !== '') {
|
|
var cookies = document.cookie.split(';');
|
|
for (var i = 0; i < cookies.length; i++) {
|
|
var cookie = jQuery.trim(cookies[i]);
|
|
// Does this cookie string begin with the name we want?
|
|
if (cookie.substring(0, name.length + 1) === (name + '=')) {
|
|
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return cookieValue;
|
|
}
|
|
|
|
// Source: https://portswigger.net/web-security/cross-site-scripting/preventing#encode-data-on-output
|
|
function htmlEncode(str){
|
|
return String(str).replace(/[^\w. ]/gi, function(c){
|
|
return '&#'+c.charCodeAt(0)+';';
|
|
});
|
|
}
|