由于同源策略的限制,你无法直接访问跨域的 iframe 页面的内容。但是,你可以通过监听 iframe 的 load 事件来获取跳转后的 src 页面地址。具体实现如下:

var iframe = document.getElementById('your-iframe-id');
iframe.onload = function() {
  var currentSrc = iframe.contentWindow.location.href;
  console.log(currentSrc); // 输出跳转后的 src 页面地址
};

在 iframe 加载完成后,会触发 load 事件,然后你可以通过 iframe 的 contentWindow 属性来获取 iframe 中的 window 对象,从而获取当前页面的地址。请注意,由于同源策略的限制,你只能获取到同域的页面地址,而无法获取跨域页面的地址。

如何获取 iframe 跳转后的 src 页面地址

原文地址: https://www.cveoy.top/t/topic/omMP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录