...

View Full Version : call function of another page



nirav
01-19-2012, 08:21 AM
<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?

devnull69
01-19-2012, 09:53 AM
Try this


var name1frame = document.getElementsByName('name1')[0].contentWindow;
name1frame.fun1();

Old Pedant
01-19-2012, 08:11 PM
Or slightly simpler


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


var frame1window = document.getElementById("frame1").contentWindow;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum