简体   繁体   English

使用Java重定向(很多)后获取最终URL

[英]Get the final URL after (lots of) redirection with Javascript

I want to get the final URL after the redirection with just Javascript. 我想用Javascript重定向后得到最终的URL。

For example I have the url http://example.com/testClient , this redirects to different places with hashes and query parameters based on client cookies. 例如,我有URL http://example.com/testClient ,它使用基于客户端cookie的哈希和查询参数重定向到其他位置。 I want to get the final URL with Javascript only. 我只想使用Javascript获得最终URL。

The URL redirects to different location, with different hash and different query parameter on different clients based on cookies, user-agent, platform, etc. URL根据Cookie,用户代理,平台等在不同的客户端上使用不同的哈希值和不同的查询参数重定向到不同的位置。

This is similar to get the original (expanded) URL of a bit.ly link with Javascript. 这类似于使用Java获取bit.ly链接的原始(扩展)URL。

Any suggestions on how to do this?? 有关如何执行此操作的任何建议?

You could use an iframe like in this example: http://jsfiddle.net/BaliBalo/qsX6U/ 您可以在以下示例中使用iframe: http//jsfiddle.net/BaliBalo/qsX6U/

iframe.addEventListener('load', function(){
    console.log(iframe.contentWindow.location.href);
}, false);

BUT there is an issue: domain of the final URL has to be the same as the one the script is running on, otherwise it will raise a cross-domain error and contentWindow properties would not be accessible. 但是存在一个问题:最终URL的域必须与脚本所运行的域相同,否则将引发跨域错误,并且无法访问contentWindow属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM