JavaScript 获取 iframe 当前 URL 的方法

作者:代码拾荒时间:2026-10-27 17:17:33浏览:286

在开发中使用 iframe 进行分页或跳转时,无法直接通过 src 属性获取内部页面的当前 URL。本文介绍了利用 parent.document 结合 contentWindow.location.href 获取 iframe 当前地址的具体代码实现及参数说明。

获取 iframe 当前 URL 的方法

在开发过程中,使用 iframe 进行分页操作时,iframe 内部页面的 URL 跳转无法直接通过 iframe 的 src 属性来获取当前地址。



以下是获取 iframe 当前 URL 的具体方法。


参考代码如下:

 
parent.document.getElementById("content_info").contentWindow.location.href

其中,content_info 为 iframe 元素的 id 属性值。

作者最新文章