如何检测iframe是否已从一个URL移动到另一个URL

How to detect if an iframe has moved from one URL to another

本文关键字:URL 一个 移动 另一个 何检测 检测 iframe 是否      更新时间:2023-09-26

我想知道是否有人能帮我解决这个问题,我有一个URL的iframe(在子域上)。iframe中的页面有一个指向另一个页面的按钮。当用户移动到iframe中的另一个页面时,我希望能够调整iframe的大小。以下是我如何调整第一页的大小。

 $disp = '<div style="border: 0px solid rgb(201, 0, 1); overflow: hidden; margin: 50px auto; max-width: 300px;">
<iframe scrolling="no" src="https://something.com" style="border: 0px none; margin-right: 188px;height: 1036px; margin-top: -380px; width: 297px;">
</iframe> 
</div>';
echo $disp;

使用onLoad可以判断iframe源是否发生了更改,如下所述:

iFrame src更改事件检测?

要点是

<iframe src="http://www.google.com/" onLoad="yourJsFunc();"></iframe>

或者,使用jQuery

$('#iframeid').load(function()
{
    alert('frame has (re)loaded');
});