如何提取iframe的重定向网址?

时间:2016-01-27 19:46:35

标签: javascript jquery redirect iframe

我搜索了很多,但没有找到(或者我没有理解那些解决方案)我正在寻找什么。我想从iframe中提取重定向网址。例如,我在iframe中嵌入了xyz.com,现在当iframe在客户端浏览器上加载时,它会被重定向到example.com /.

我想提取重定向的网址,即example.com /

由于

1 个答案:

答案 0 :(得分:1)

如果您的iframe位于同一个域中,您可以选择iframe,选择iframe的内容,选择您的重定向网址,使用window.location重定向:

var iframe = document.getElementById('iframeId');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
var redirect = innerDoc.getElementById('redirectURL').innerHTML;
window.location = redirect;

如果不是,则由于跨站点脚本而无法获取内容

相关问题