简体   繁体   English

如何在没有onload事件的情况下检测iframe何时更改位置并触发功能?

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

I want to detect when my IFrame changes the location, but not using onload event, actually i need to trigger a function just after the location of the IFrame changes to validate just a list of urls and if the new location is in my list do something on the parent view. 我想检测我的IFrame何时更改位置,但不使用onload事件,实际上我需要在IFrame的位置更改后立即触发一个函数,以仅验证网址列表,并且如果新位置在我的列表中,请执行某项操作在父视图上。 this is my actual function that i need to trigger but just before the iframe new url start to loads thats why the event onload doesn't match with what i need 这是我需要触发的实际功能,但是在iframe新网址开始加载之前,这就是为什么事件onload与我需要的不匹配的原因

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" });
        }
    }

Update actually i needed to validate the new url or location that was being loaded in the frame in order to trigger a function that show or hide the navigation bar deppending on the new url so it wouldn't seem like delayed 更新实际上我需要验证框架中正在加载的新URL或位置,以便触发显示或隐藏新URL上紧靠的导航栏的功能,这样看来就不会延迟

i figure out how to do the functionality i was seeking for with help from here: How can I get Iframe event before load? 我在这里寻求帮助时, 如何找到所需的功能: 如何在加载前获取Iframe事件? this is my final code that kind of hi-jack the links to get the functionality 这是我的最终代码,这种劫持链接可以获取功能

 $('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"));
        });
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM