Quick Copy

Some commonly used functions, available here for easy copy and pasting.

Contents
GetQuery (Javascript) Copy | Permalink | This function's source

//http://stackoverflow.com/a/901144/5511561
function getQuery(name) {
    var  url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}
                        

replaceAll (Javascript) Copy | Permalink | This function's source

//http://stackoverflow.com/a/17606289/5511561s
String.prototype.replaceAll = function(search, replacement) {
    var target = this;
    return target.replace(new RegExp(search, 'g'), replacement);
};
                        

Loop Through Object (Javascript) Copy | Permalink | This function's source

//https://stackoverflow.com/a/684692/5511561 (slightly adapted)
for (var key in myObject) {
    if (myObject.hasOwnProperty(key)) {
        console.log(key + " -> " + myObject[key]);
        // key -> value
    }
}
                        

Html Redirect (HTML) Copy | Permalink | This function's source
<meta http-equiv="refresh" content="0; url=http://example.com/page/page.html" />