Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

Call Parent Frame JavaScript

--- I have a frame HTML page: ----------------------------------------------
<frameset rows="74,*">
 <frame src="header.html" name=header>
 <frame src="body.html" name=body>
</frameset>

--- in the header.html 'script' section I have functions: ------------------
function click(imageLoc)
function headerRollOut(num)
function headerRollOver(num)
function navigatorRoll(mousePos)

Now for the question.  I want to call the functions in the header.html (header) page from the html in the body.html (body) page.  That is I don't choose to repeat all my functions that I wrote in my header.html in my body.html.  I don't want the same code in both areas.  Is there something like:
         parent.frames['header'].click(imageLoc)
that will call a javascript function from another frame?  Please help!  Thanks so much!  How the heck do I do this??
0
rw263
Asked:
rw263
1 Solution
 
sybeCommented:
yes, it should work as you described.

maybe it is even easier to write the functions (and varibles if you want) in the frameset-page.

================

<script>
var MyVar1 = ...

function MyFunction1() {}
function MyFunction2() {}
function MyFunction3() {}
</script>

<frameset rows="74,*">
<frame src="header.html" name=header>
<frame src="body.html" name=body>
</frameset>

=================

you can call from the frames by:

parent.MyFunction1()

and access variables like

newvar = parent.Myvar1


0
 
rw263Author Commented:
I kept the script in the header.html and called the script from the body.html like: onMouseOver="parent.header.navigatorRoll('Over')" and it doesn't work.  If I have in the header.html onMouseOver="navigatorRoll('Over')" it works.  How do I call the SAME script from a different frames html?

0
 
cutetechCommented:
It supposes to be work nice. Can you post your script? It may be help.
0
 
alamoCommented:
I am assuming that "parent.header.navigatorRoll()" does not work. It should - I duplicated your setup (from what you posted) and it worked for me, both Netscape and IE3.

I have seen things like this before, though, where due to the way the html is written "parent" doesn't get the job done. (Usually the error will be something like "parent.header has no properties"). Try the following:
top.header.navigatorRoll()
or
parent.parent.header.navigatorRoll()

If neither of these works... please be more specific. What error does it give?
0
 
rw263Author Commented:
Sorry, my bad, the original suggestion did work, I didn't know how to recall my bad reply.  I originally had local problems and that is what caused it.  Thanks for all the help!!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now