如何在没有加载事件的情况下检测Iframe何时更改位置并触发函数

how to detect when an Iframe change location without onload event and trigger a function?

本文关键字:何时更 Iframe 位置 函数 检测 情况下 加载 事件      更新时间:2023-09-26

我想检测我的IFrame何时更改位置,但不使用onload事件,实际上我需要在IFrame的位置更改后立即触发一个函数来验证URL列表,如果新位置在我的列表中,则在父视图上执行操作。这是我需要触发的实际函数,但就在iframe新url开始加载之前,这就是为什么加载的事件与我需要的不匹配

function onLoadFrame() {
        var a = document.getElementById("cont").contentWindow.location.href;
        if ((a.indexOf("MainDashboard") > -1) || (a.indexOf("AccountManagement") > -1) || (a.indexOf("workspace_home") > -1)) {
            $('#nav-bar').fadeOut(0);
            $('#u-left-panel').fadeOut(0);
            $("#content").css({ marginLeft: "0px" });
        } else {
            $('#nav-bar').fadeIn(0);
            $('#u-left-panel').fadeIn(0);
            $("#content").css({ marginLeft: "40px" });
        }
    }

更新实际上,我需要验证正在加载到框架中的新url或位置,以便触发一个函数,显示或隐藏依赖于新url的导航栏,这样就不会看起来像延迟的

我在这里找到了如何在帮助下实现我想要的功能:如何在加载前获取Iframe事件?这是我的最后一个代码,这种hi jack链接可以获得的功能

 $('a[target="contenido"]').bind('click', function () {
        activateNavBar($(this).attr("href"));
    });
    function bindFunctionToLinks() {
        $("#cont").contents().find('a[target = "contenido"]').bind("click", function () {
            activateNavBar($(this).attr("href"));
        });
    }