正在获取另一个URL重定向到的URL

Getting the URL another URL redirects to

本文关键字:URL 重定向 另一个 获取      更新时间:2023-09-26

我正试图获取另一个URL重定向到的URL。

例如,我去http://www.example.com/redirect.现在此页面将我重定向到http://www.some-other-domain.com/?language=english.

如何获得http://www.some-other-domain.com/?language=englishURL使用Javascript,只知道http://www.example.com/redirectURL

如果您的浏览器设置为允许打开新窗口或选项卡,则可以执行以下操作:

var whndl, otherURL;  //whndl=window-handle
function prep()
{ window.name="thiswindow";
  whndl = window.open("http://www.example.com/redirect", "otherwindow");
  setTimeout("fetchURL();", 500); //half-second for page to at least partly load
  return;
}
function fetchURL()
{ otherURL = whndl.document.URL;  //should be the redirected URL
  whndl.close();  //if you don't need it open any longer
  return;
}

这样做的时候,你可能可以隐藏"另一个窗口",这样就没有人看到它,也许可以使用"隐藏"技巧(我承认,我现在不知道这个技巧到底是什么)。