0

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. 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

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

  • 1
    Have whatever is triggering the url change in the iframe call a function in your parent? Not nearly as nice, but have a function that polls the iframe's location? Or try the second answer from here: http://stackoverflow.com/questions/2429045/iframe-src-change-event-detection – Robert McKee Nov 11 '15 at 17:30
  • Is the iframe content from your own site or it can be any site's content? – Asons Nov 11 '15 at 17:33
  • the content on the frame would be an url of my own site and im triggering the function onloadframe with the event onload, this is the iframe code ` – theoneomega Nov 11 '15 at 17:36
  • Then just follow @RobertMcKee's links and tip ... it has the solution for you. – Asons Nov 11 '15 at 18:21
  • actually the onload event triggers after the iframe finish to load everything so the function that i need to trigger trigger after the iframe content is ready and that doesn't works for me...i need to change IFrame src, then trigger the function and just after that start to load the content of the new url – theoneomega Nov 11 '15 at 22:02

1 Answers1

0

i figure out how to do the functionality i was seeking for with help from here: How can I get Iframe event before load? 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"));
        });
    }
Community
  • 1
  • 1