Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Execute functions in frames from a parent frame

Posted on 2009-05-05
7
Medium Priority
?
423 Views
Last Modified: 2013-11-18
Is it possible to call functions that are within html files when they are displayed in frames? I need to call a function containing document.body.clientHeight and clientWidth to get the dimensions of a frame and store them in a file for future purposes. I'm thinking about having an html file with an iframe that contains the html file containing the frame html. From the html file containing the iframe, I would need to call a function in each of the frames inside the iframe. Is this too confusing? the code is provided to show you what the html file inside the iframe would display. As you can see, this html file would display more html files inside frames. From the html files in the frames, there is a function I would like to call from the FRAME HTML. This function returns the height and width of the frame the html file is displayed in.
FRAME HTML
<html>
 
<frameset rows = "3%,82%,15%" frameborder = "yes" noresize="noresize">
<frame src="Ticker.html">
<frameset cols="35%,65%" frameborder = "yes">
<frame src="stuff.html">
<frame src="cursor.html" noresize="noresize">
</frameset>
 
<frameset cols="25%,75%">
<frame src="stuff.html">
<frame src="Ticker.html">
 
</frameset>
</frameset>
</html>

Open in new window

0
Comment
Question by:sunnymock
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 10

Expert Comment

by:bugada
ID: 24310223
First give a different ID to each <frame> in the framesets.

To get clientWidth call the instruction from the page containing the iframe, passing the correct frame id instead of "frameID" and the correct iframe name instead of "youriframe".

Restrictions: works in IE only and only all the html pages involved come from the same domain.
document.youriframe.document.getElementById(frameID).document.body.clientWidth

Open in new window

0
 
LVL 10

Expert Comment

by:bugada
ID: 24310332
Reading better your question, I think you have the functions ready in every frames.
The you can use this code to access those functions (in my example every frames contains the function show(), but you can dicriminate on the frame id/name).

Same restrictions as the example above.
      var d = document;
      var f = document.youriframe;
      var f2 = f.document.frames;
         for (var i = 0; i < f2.length; i++) {
               f2[i].show();
         }
      }

Open in new window

0
 
LVL 10

Expert Comment

by:bugada
ID: 24310343
an optimized version ;-)
var f2 = document.youriframe.document.frames;
for (var i = 0; i < f2.length; i++) {
   f2[i].show();
}

Open in new window

0
Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

 

Author Comment

by:sunnymock
ID: 24316863
Sorry, but I forgot to mention that I need it to work in Firefox. Will this last method work in Firefox? Thanks. I haven't tried it yet but I'm sure it'll be what I'm looking for.
0
 

Author Comment

by:sunnymock
ID: 24316869
It doesn't have to work in IE. Solely firefox would be great.
0
 
LVL 10

Expert Comment

by:bugada
ID: 24320337
This is a version FF /IE compatible, but you have to assign the id = "youriframe" (or whatelse according to the javascript) to the div, because FF doesn't know the document.frames collection.
  <script>
   window.onload = function(e) {
      var oIframe = document.getElementById("youriframe");
      var oDoc = oIframe.contentWindow || oIframe.contentDocument;
      if (oDoc.document) {
          oDoc = oDoc.document;
      }
      var fs = oDoc.getElementsByTagName("frame");
      for (var i = 0; i < fs.length; i++) {
         var fDoc = fs[i].contentWindow || fs[i].contentDocument;
         fDoc.show();
      }
   }
  </script>

Open in new window

0
 
LVL 10

Accepted Solution

by:
bugada earned 1220 total points
ID: 24320401
sorry i mentioned a div in the previous message: substitute it with 'iframe' :-)
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

721 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