-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.js
More file actions
29 lines (26 loc) · 920 Bytes
/
helper.js
File metadata and controls
29 lines (26 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Quick function to make an http request.
var httpGetAsync = function(theUrl, callback){
var xmlHttp = new XMLHttpRequest(); // create the http request object
// Set up an event listener for when the request is returned.
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
// Create the request.
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
};
// Quick function to extract the domain from the url string.
var extractDomain = function (url) {
var domain;
//find & remove protocol (http, ftp, etc.) and get domain
if (url.indexOf("://") > -1) {
domain = url.split('/')[2];
}
else {
domain = url.split('/')[0];
}
//find & remove port number if there is one
domain = domain.split(':')[0];
return domain;
};