Solved

Call Parent Frame JavaScript

Posted on 1998-07-08
5
233 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now