Solved

Call Parent Frame JavaScript

Posted on 1998-07-08
5
236 Views
Last Modified: 2012-05-04
--- 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
Comment
Question by:rw263
5 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 1266351
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
 

Author Comment

by:rw263
ID: 1266352
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
 
LVL 1

Expert Comment

by:cutetech
ID: 1266353
It supposes to be work nice. Can you post your script? It may be help.
0
 
LVL 6

Accepted Solution

by:
alamo earned 200 total points
ID: 1266354
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
 

Author Comment

by:rw263
ID: 1266355
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question