How to call the functon inside frame page?

Sciter Forums Script How to call the functon inside frame page?

Tagged: ,

This topic contains 2 replies, has 2 voices, and was last updated by  stackoverflow_user 1 month, 2 weeks ago.

  • Author
    Posts
  • #49343

    stackoverflow_user
    Participant

    Hi,

    How to call the function inside frame page from parent?

    main.htm

        <script type="text/tiscript">
    	function CallFrameFunction()
            {
                const content = $(frame#content);
                content.inside();// 1.not work
                content.$inside();// 2.not work
                content[0].inside();// 3.not work
                content[0].$inside();// 4.not work
            }
        </script>
    
        <frame #content src="frame.htm" aria-label="Content" ></frame>

    frame.htm

        <script type="text/tiscript">
        function inside()
        {
            stdout.println("inside() called...");
        }
        </script>

    Thanks

  • #49350

    Andrew
    Keymaster

    In script (Sciter’s script or JavaScript), when you declare function like this:

    <script type="text/tiscript">
        function inside()
        {
            stdout.println("inside() called...");
        }
    </script>

    it actually gets compiled as a member function of some namespace (object).
    In JS that namespace object is accessible by variable with quite strange name – window.
    In Sciter you can get reference of that namespace as self.ns so:

    <script type="text/tiscript">
        function inside()
        {
            stdout.println("inside() called...");
        }
        assert inside === self.ns.inside;
    </script>

    And finally, to call function defined in a frame from its host document:

    var frame = $(frame#content);
    var documentInFrame = frame[0];
    documentInFrame.ns.inside(); // calling function declared in namespace of documentInFrame
  • #49358

    stackoverflow_user
    Participant

    Thanks a lot.

You must be logged in to reply to this topic.