The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Getting auto/100% iframe height using _spBodyOnLoadFunctionNames?
JRBobDobbs
post Feb 1 2010, 03:03 PM
Post #1


Member
***

Group: Members
Posts: 41
Joined: 2-November 09
Member No.: 10,212



Hi there. I've pieced together as much as I could from searching the problem with Google, and now I need your help. I want to get my iframe's height to be "auto", to adjust automatically depending on the content inside it. I have read that using _spBodyOnLoadFunctionNames is one of the best ways, and it seemed simpler than other ways, so it is what I have tried. Please note that this is the first time I have ever tried using Javascript.

This is what I have so far:

<script type="text/javascript" language="javascript" >

_spBodyOnLoadFunctionNames.push("resizeIframe")

"function resizeIframe("TMAframe") {

var iframe = window.parent.document.getElementById("TMAframe");
var container = document.getElementById("TMAframecontent");

iframe.style.height = container.offsetHeight + "px";

}"
</script>

As you can see, I have given an ID to the iframe in question, and I have put in a div box the contents from another page of my website that I want to see in the iframe and I gave that div box an ID as well. But at this point nothing happens, the iframe is just like 200px high (as if I had just put 100% height without doing anything else, which doesn't work).

Here is the iframe in question:

<iframe id="TMAframe" scrolling="no" width="285px" frameborder="0" marginheight="0px" src="http://metalarchives.transcix.com/news.html">
Your browser does not support iframes.
</iframe>

I have no other iframes or other complex processes/things on that webpage so I don't think there are any conflicts.

I think the main difficulty could be where to put the above java code. I tried in the header, in the body, and in the body tag itself (<body [...]>), but it never worked at all. I have looked on Google but it is never explicitly stated how to insert the java code. I come across lots of talk about a "master page", but I don't know what that is. All I want is for an iframe on a page on my website to have auto height.

Any assistance is much appreciated, thanks in advance for your time.

PS - I don't have to list anything (IDs, etc) in my CSS style sheet for this, correct?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Feb 1 2010, 03:56 PM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



I thought _spBodyOnLoadFunctionNames was a feature of MS SharePoint. Do you use SharePoint?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
JRBobDobbs
post Feb 1 2010, 04:04 PM
Post #3


Member
***

Group: Members
Posts: 41
Joined: 2-November 09
Member No.: 10,212



No I do not use SharePoint, I am not aware of what "SharePoint" is. Does this mean that I cannot use _spBodyOnLoadFunctionNames?

If so, how would you suggest I proceed? All the explanations I found on Google about how to get auto margins assume that you already know something about it, and since I do not, I cannot use them... (unless you know of a more simple and explicit explanation)

Otherwise if you or someone else here could explain it to me yourself, that would be really great.

This post has been edited by JRBobDobbs: Feb 1 2010, 04:07 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Feb 1 2010, 04:19 PM
Post #4


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



QUOTE(JRBobDobbs @ Feb 1 2010, 10:04 PM) *

No I do not use SharePoint, I am not aware of what "SharePoint" is.


Neither am I. I just know it's a MS technology of sorts. Googling turned up this.
http://en.wikipedia.org/wiki/Sharepoint

QUOTE
Does this mean that I cannot use _spBodyOnLoadFunctionNames?

That's what I think. Found this.

In most cases SharePoint pages are based on a master page that contains the “body” element. These content pages can’t directly add a function to the body’s onload event. In order to work around this limitation, SharePoint provides the “_spBodyOnLoadFunctionNames” array. When the body is loaded, the onload event handler executes each function whose name is contained in this array. We added “fillDefaultValues” to the array so that it would run when the body’s onload event fires.
http://blogs.msdn.com/sharepointdesigner/a...form-field.aspx

QUOTE
If so, how would you suggest I proceed? All the explanations I found on Google about how to get auto margins assume that you already know something about it, and since I do not, I cannot use them... (unless you know of a more simple and explicit explanation)


You want to resize the iframe to fit its content, right? It can't be done with margins. JavaScript must first know the dimensions of the page loaded in the iframe, then it can work with that. Try searching something like this.
http://google.com/search?q=dynamically+resize+iframe
http://google.com/search?q=dynamic+iframe+height
http://google.com/search?q=iframe+fit+content
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
JRBobDobbs
post Feb 1 2010, 04:34 PM
Post #5


Member
***

Group: Members
Posts: 41
Joined: 2-November 09
Member No.: 10,212



QUOTE(pandy @ Feb 1 2010, 04:19 PM) *

You want to resize the iframe to fit its content, right? It can't be done with margins. JavaScript must first know the dimensions of the page loaded in the iframe, then it can work with that. Try searching something like this.
http://google.com/search?q=dynamically+resize+iframe
http://google.com/search?q=dynamic+iframe+height
http://google.com/search?q=iframe+fit+content


You have definitely suggested some good search terms there for me to use. I clicked the first result on the first search terms you suggested and I think my question is solved now. Thanks Pandy!

This post has been edited by JRBobDobbs: Feb 1 2010, 04:34 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th April 2024 - 01:50 PM