Skip to content

Instantly share code, notes, and snippets.

@adeelnasir
Last active Jun 13, 2018
Embed
What would you like to do?
// **********************************************
// Customized load process from here...
// **********************************************
// **********************************************
// Auto redirect based on client request's IP address...
// **********************************************
(function () {
function loadScript(url, callback) {
var script = document.createElement("script");
script.type = "text/javascript";
console.log('Loading jQuery');
if (script.readyState) { //IE
script.onreadystatechange = function () {
if (script.readyState === "loaded" || script.readyState === "complete") {
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function () {
callback();
};
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
loadScript("/adfs/portal/script/jquery-3.min.js", function () {
// jQuery loaded
console.log('jQuery loaded');
var ipService = "https://{Web-Server-Web-API-URL}/api/resolver/get"; //Put your API URL here
var getIp = function (callback) {
console.log('Getting ClientIP...');
$.ajax({
url: ipService,
dataType: 'json',
contentType: 'application/json',
success: function (data, status, xhr) {
if (data == null || data.RedirectName == null)
return;
var res = data.RedirectName;
console.log(res);
callback(res);
},
error: function (xhr, status, errorString) {
console.log(errorString);
}
});
}
$(document).ready(function () {
try {
getIp(function (redirect) {
if (typeof HRD !== "undefined") {
HRD.selection(redirect);
}
}
}
catch(err) {
console.log(err);
}
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment