Javascript 替换url中用于登录的域

Javascript 替换url中用于登录的域,javascript,login,bookmarklet,gateway,Javascript,Login,Bookmarklet,Gateway,在我的大学IP域之外工作时,我必须使用登录服务器访问出版商网站。 大多数url的格式为http://pubs.domain.org/XXX.html转换为http://pubs.domain.org.gateway.university.edu/XXX.html 问题是:大多数出版商的网站都有一个无用的搜索工具,所以我使用谷歌登陆普通网站,而在大学以外的地方使用知识网往往无法连接到出版商。我发现,只要我在最后一个小时内进行了身份验证,手动替换URL就会起作用 我正在寻找一种使用bookmarkl

在我的大学IP域之外工作时,我必须使用登录服务器访问出版商网站。 大多数url的格式为
http://pubs.domain.org/XXX.html
转换为
http://pubs.domain.org.gateway.university.edu/XXX.html

问题是:大多数出版商的网站都有一个无用的搜索工具,所以我使用谷歌登陆普通网站,而在大学以外的地方使用知识网往往无法连接到出版商。我发现,只要我在最后一个小时内进行了身份验证,手动替换URL就会起作用

我正在寻找一种使用bookmarklet自动完成此操作的方法。我发现这个问题似乎正是我所寻找的,但我以前从未使用过javascript,也无法适应它。

谢谢

试试看

window.location.href = window.location.href.replace("://pubs.domain.org","://pubs.domain.org.gateway.university.edu");

我最近也遇到过这种情况。由于您希望在主机名后附加后缀,但在其他情况下保持URL不变,因此可以直接编辑window.location.hostname以触发重新加载:

javascript:window.location.hostname += '.gateway.university.edu';
或与关闭:

javascript:(function() {
  window.location.hostname += '.gateway.university.edu';
})();
javascript:(function() {
  window.location.hostname += '.gateway.university.edu';
})();