How to access parent Iframe from JavaScript

后端 未结 9 1625
梦毁少年i
梦毁少年i 2020-11-22 07:50

Well, I have an IFrame, which calls a same domain page. My problem is that I want to access some information from this parent Iframe from this called page (from JavaScript).

9条回答
  •  广开言路
    2020-11-22 08:50

    // just in case some one is searching for a solution
    function get_parent_frame_dom_element(win)
    {
        win = (win || window);
        var parentJQuery = window.parent.jQuery;
        var ifrms = parentJQuery("iframe.upload_iframe");
        for (var i = 0; i < ifrms.length; i++)
        {
            if (ifrms[i].contentDocument === win.document)
                return ifrms[i];
        }
        return null;
    }
    

提交回复
热议问题