Javascript / jQuery: calling a function in another frame

I am new to the DOM and JavaScript, and run into some problems when trying to call a function defined in a frame from the context of a top-level frame or Firebug.

Given the following set of frames:

<html>
    <body>
    <frameset cols="*" rows="81,*">
        <frame id="topFrame" tabindex="1" name="topFrame" noresize="noresize" scrolling="No" src="hometop.aspx"/> 
        <frameset border="0" cols="214,*" frameborder="no" framespacing="0">
            <frameset border="0" cols="*" frameborder="no" framespacing="0" rows="70,*">
                <frame tabindex="-1" id="chatFrame" name="chatFrame" scrolling="No" noresize="noresize" src=""/>
                <frame tabindex="-1" id="leftFrame" name="leftFrame" noresize="noresize" src="leftFrame.aspx"/>
            </frameset> 
            <frame tabindex="-1" id="mainFrame" name="mainFrame" src=""/>
        </frameset> 
        <noframes>Your browser does not support frameset.</noframes> 
    </frameset>
    </body>
</html>

I am trying to write a javascript hook that will call the javascript function defined in #leftFrame when the first document is opened first. I am doing this in a Firebug session with jQuery loaded .

jQuery ("# ​​leftFrame") returns the DOM element of the frame. Now I would like to execute my function (openLink defined in the plain old script tag in leftFrame.aspx) in the context of the frame. I understand that the function will be a DOM node under the leftFrame document element. However, I cannot get the frame document.

:

 jQuery("#leftFrame").document
 jQuery("#leftFrame").contentDocument
 jQuery("#leftFrame").find("html")

DOM Firebug openLink DOM, .

- ?

+3
1
$('#leftFrame')[0].contentWindow.document
$('#leftFrame')[0].contentWindow.functionName()

. jQuery contents() iframe node, .

+6

Source: https://habr.com/ru/post/1760041/


All Articles