/    Sign up×
Community /Pin to ProfileBookmark

My automaticly resize iframe script won’t work

I have a site with an iframe in which I show the chosen menuitem.

I have this script:
<script language=”JavaScript” type=”text/JavaScript”>
<!–
function setIframe( html_document )
{
document.all( ‘main’ ).src = html_document;
document.all( ‘main’ ).style.height = document.all( ‘main’ ).body.clientHeight();
}
//–>
</script>

And the tag for clicking the menu items is like this:
<a href=”javascript:setIframe( ‘news.htm’ )”>News</a>

The frames content changes as it should, but I don’t the the height to fit the contents of the iframe…

This problem is driving me nuts. If you know what I’m doing wroing, please tell me. I’m new to JavaScript if that isn’t obvious if you refer to my posts in this forum…

Thank you.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@swonSep 14.2003 — Hi,

may this one can do it:

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

<!--

function setIframe( html_document )

{

document.all.main.src = html_document;

document.all.main.style.height = document.all.main.document.body.scrollHeight;

}

//-->

</script>

And the tag for clicking the menu items is like this:

<a href="javascript:setIframe( 'news.htm' )">News</a>

<iframe name=main id=main src=file.html style="height:100;"></iframe>
Copy linkTweet thisAlerts:
@EnselicauthorSep 14.2003 — According to w3c, you should have "" around your attribute values. I also heard that .all. was MSIE specific so I changed to getElementById() but that didn't work either.
Copy linkTweet thisAlerts:
@swonSep 14.2003 — I thought you knew that document.all is IE specific.

With document.getElementById() it looks something like this:

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

<!--

function setIframe( html_document )

{

elm = document.getElementById('main');

elm.src = html_document;

elm.style.height = elm.document.body.scrollHeight;

}

//-->

</script>

And the tag for clicking the menu items is like this:

<a href="javascript:setIframe( 'news.htm' )">News</a>

<iframe name="main" id="main" src="neu.html" style="height:100;"></iframe>

(it works also without the "" in the attributes values)
×

Success!

Help @Enselic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...