javascript - 获取子域名并使用greasemonkey将其加载到url

标签 javascript url greasemonkey

我有 URL http://somesubdomain.domain.com (子域可能会有所不同,域始终相同)。需要使用greasemonkey获取子域名并使用类似domain.com/some/path/here/somesubdomain的内容重新加载页面(或者使用URLdomain.com/some/path/here/somesubdomain等打开一个新窗口)。

最佳答案

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);

关于javascript - 获取子域名并使用greasemonkey将其加载到url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1282726/

相关文章:

javascript - ajax 调用后保留 JavaScript 变量

javascript - npm 运行开发脚本错误

javascript - 计算上周的活跃用户数?

javascript - 为什么我的网址中没有对点字符进行编码?

ruby-on-rails - 如何停止rails应用程序中的链接以域为前缀

javascript - nextElementSibling 卡住 firefox

javascript - 在脚本 src 中使用本地存储值

regex - 如何使用 Perl 从纯文本中提取 URL?

javascript - 使插件适用于所有主要浏览器的精益和快速方法? Firefox、Chrome、[歌剧、Internet Explorer、Safari]

javascript - 通过JS彻底清空一个页面,不重定向到:blank?左右