-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_url.js
48 lines (42 loc) · 1.28 KB
/
parse_url.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function parse_url(url){
var token = '';
var ret = new Array();
var arg = new Array();
var query = '';
if(url.length <= 0) return false;
var full_url_path = url.substr( 0, url.indexOf('?') <= 0 ? url.length : url.indexOf('?') );
ret['url'] = full_url_path;
if( url.indexOf('?') > 0 )
{
query = url.substr( url.indexOf('?') + 1 );
}
ret['query'] = query;
ret['path'] = full_url_path.substr( 0, url.lastIndexOf('/') + 1 );
if( ret['path'].match( /^http.*\.[a-z]{2,4}/g ) )
{
var tmp = ret['path'].substr( ret['path'].indexOf('://') + 3 );
ret['domain'] = tmp.substr( 0, tmp.indexOf('/') );
}
var query_string = url.substr( url.indexOf('?')+1 );
if( query_string.indexOf('&') > 0 )
{
arg = query_string.split('&');
}
else
{
arg[0] = query_string;
}
for(var i=0; i<arg.length; i++)
{
if( arg[i].indexOf('=') >= 0 )
{
token = arg[i].split('=');
ret[token[0]] = token[1];
}
else
{
ret[token[0]] = '';
}
}
return ret;
}