Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

change iFrame height from child function

Posted on 2004-10-28
9
Medium Priority
?
1,867 Views
Last Modified: 2012-06-27
Can you change an iFrame height dimensions from a function with-in the child frame?

I am doing a page on my work intranet which is only updateable via an online tool which lets you write HTML (only within the <BODY> tags), but strips out any JavaScript.

I can however use small amounts of JavaScript using onload, onclick, onmouseover... elements etc...

So I have imbedded an iFrame on the page which is just a dynamic table, but because I don't know how long the table will be, it causes scrollbar to appear.

I tried to change this from the onload element of the iFrame by doing this:

<IFRAME onload="this.style.pixelHeight=this.scrollHeight;" style="OVERFLOW: auto; WIDTH: 100%;height:;" src="mytablehtml.asp" frameBorder=0></IFRAME>

But for some reason this does not work??

So I would like to include a function inside the child frame that will test how tall it is and tell it's parent to resize if possible.

*** OR ***

Would like to have my current method corrected if wrong.

Reg's
m8rix
0
Comment
Question by:m8rix
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 25

Assisted Solution

by:devic
devic earned 1600 total points
ID: 12439896
example:
======================
<IFRAME name=myiframe onload="this.style.height=document.frames.myiframe.document.body.scrollHeight;"
style="OVERFLOW: auto; WIDTH: 100%;height:;" src="child.html" frameBorder=0></IFRAME>
0
 
LVL 31

Assisted Solution

by:GwynforWeb
GwynforWeb earned 400 total points
ID: 12439942
you can detect the iframe height in a child and resize it, eg

<IFRAME id="f" src="child.htm ">
</IFRAME>

then in child.htm

<input type="button" onclick="if (parent.document.getElementById('f').height < 250) parent.document.getElementById('f').height=300">
0
 
LVL 10

Author Comment

by:m8rix
ID: 12440032
Thanks for your comments guys, but both of these suggestions failed. I get an access denied error
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Assisted Solution

by:devic
devic earned 1600 total points
ID: 12440042
you can not change iframe, if the iframe is not in the same domain
0
 
LVL 10

Author Comment

by:m8rix
ID: 12440132
Thanks for that, my two pages are on different domains :(

Is there any attributes you can get using:
document.frames.myiframe.document.body.SomeAttribute

I tried to read the innerHTML of the iFrame and got the same error.

Also, because I created the page that is included in the iFrame, can I change the security of the page somehow to allow the parent to read it?
0
 
LVL 25

Accepted Solution

by:
devic earned 1600 total points
ID: 12440190
no way and forget all what beginns with "document." on foreign domain, because it's not your document.





you can use XMLHTTP:
=====================================
<html>
<body onload=init()>

<center><h2>hello m8rix!</h2></center>
<hr>
<script>
function LoadPage(theURL,theID)
{


   var objSrvHTTP;
       objSrvHTTP = new ActiveXObject("Msxml2.XMLHTTP.4.0");
       objSrvHTTP.open ("GET",theURL,false);
       objSrvHTTP.send ("");

        document.getElementById(theID).innerHTML=objSrvHTTP.responseText;

}

function init()
{
      LoadPage("http://www.yahoo.com","yahoo")
      LoadPage("http://www.ebay.com","ebay")
}
</script>
<table width=555 cellspacing=0 cellpadding=0 border=3>
      <td valign=top id=yahoo></td>
      <td valign=top id=ebay></td>
</table>

</body>
</html>
0
 
LVL 10

Author Comment

by:m8rix
ID: 12440658
Thankyou... All comments made were very good. Thus leaving behind a great reference for the future.

reg's
m8rix
0
 
LVL 25

Expert Comment

by:devic
ID: 12440712
thank you too!
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12440945
thx :-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

609 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