diff options
author | Jakob Stendahl <jakob.stendahl@outlook.com> | 2017-10-25 12:11:37 +0200 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2017-10-25 12:11:37 +0200 |
commit | 883d5171ef945fc6312cb7be9e4c771199f005bd (patch) | |
tree | cc9365c1bd47b704f8cdab1d02aee0e4fe461b75 /webPage | |
parent | 96236ad238dfce3ec8bdc330b44d0b319c8447ef (diff) | |
download | Luxcena-cs-883d5171ef945fc6312cb7be9e4c771199f005bd.tar.gz Luxcena-cs-883d5171ef945fc6312cb7be9e4c771199f005bd.zip |
Added shared javascript to a header-file
Diffstat (limited to 'webPage')
-rw-r--r-- | webPage/script.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/webPage/script.js b/webPage/script.js new file mode 100644 index 0000000..8de1803 --- /dev/null +++ b/webPage/script.js @@ -0,0 +1,45 @@ +function fixNoNetwork() { + if (getParameterByName("l") != null) { + document.getElementById("homePageAddr").href = "/?l=1"; + document.getElementById("settingsPageAddr").href = "/settings?l=1"; + return; + } + + try { + var xhttp = new XMLHttpRequest(); + xhttp.onerror = function onError(e) { + //alert("Error " + e.target.status + " occurred while receiving the document."); + var hrefAddr = window.location.href + "?l=1"; + window.location.replace(hrefAddr); + }; + xhttp.open("GET", "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css", true); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.send(); + } catch (e) { + console.log(e); + } +} + +function ajax_request(adress, callback_function) { + /* A simple ajax request wrapper + Doesn´t return anything else than the callback */ + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + callback_function(this.responseText); + } + }; + xhttp.open("POST", adress, true); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.send(); +} + +function getParameterByName(name, url) { + if (!url) 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, " ")); +} |