javascript - A better way to create a URL based on window.location.href? -
the code have right now:
setdomain: function() { var currenturl = window.location.href; var ufragment = currenturl.split('\n'); var domain = ""; if(currenturl.match(/<removed>/)) { domain = ufragment[0] + '//' + ufragment[2] + '/' + ufragment[3] + '/'; } else { domain = ufragment[0] + '//' + ufragment[2] + '/'; } this.domain = domain; },
this function decides domain script should use. @ work, have internal testing sites subdomain.domain.tld/sitename
, subdomain.domain.tld:81/sitename
the code splits current url / , appends http://
, domain.subdomain.tld
, , sitename
i looking solution because using ufragment[0]
, while need, ugly. suggestions?
Comments
Post a Comment