Get subdomain and load it to url with greasemonkey

前端 未结 4 488
悲哀的现实
悲哀的现实 2020-12-13 17:56

I am having the URL http://somesubdomain.domain.com (subdomains may vary, domain is always the same). Need to take subdomain and reload the page with something like domain.

4条回答
  •  暖寄归人
    2020-12-13 18:54

    var full = window.location.host
    //window.location.host is subdomain.domain.com
    var parts = full.split('.')
    var sub = parts[0]
    var domain = parts[1]
    var type = parts[2]
    //sub is 'subdomain', 'domain', type is 'com'
    var newUrl = 'http://' + domain + '.' + type + '/your/other/path/' + subDomain
    window.open(newUrl);
    

提交回复
热议问题