Monday, February 21, 2011

Get subdomain and load it to url with greasemonkey.

Hi! 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.com/some/path/here/somesubdomain using greasemonkey (or open a new window with URL domain.com/some/path/here/somesubdomain, whatever).

From stackoverflow
  • 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);
    
    Alex : Thank you, it works!

0 comments:

Post a Comment