Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    call function of another page

    <frameset rows="30%,70%>
    <frame src="page1.html" name="name1" frameborder="0"></frame>
    <frame src="page2.html" name="name2" frameborder="0"></frame>
    </frameset>

    in above code I used page1.html & page2.html as frame. Both include same javascript file having two function name fun1() & fun2().

    as both are separate frame both have there own copy function

    page1.html
    fun1()
    fun2()
    page2.html
    fun1()
    fun2()

    I call fun2() from page2.html and inside that function I want to call page1.html's fun1().

    fun1() in page1.html and fun1() in page2.html both return different result because of there global variables.

    Is there any way to call fun1()-page1.html from the fun2()-page2.html?

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    Try this
    Code:
    var name1frame = document.getElementsByName('name1')[0].contentWindow;
    name1frame.fun1();

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,576
    Thanks
    80
    Thanked 4,497 Times in 4,461 Posts
    Or slightly simpler
    Code:
    var name1frame = document.frames["name1"].contentWindow;
    But personally, I always just give id's to my frames, instead of or in addition to the names, and then use
    Code:
    var frame1window = document.getElementById("frame1").contentWindow;
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •