Jump to content

iframe height


sandy1028

Recommended Posts

<div class="sectabsbg">
<ul id="sectabs" class="sectabs">
<li>2011</li>
</ul>
</div>
<div class="sectabsbgnew">
<ul class="sectabsnew">
<li>2010</li>
</ul>
</div>

 

 

I am calling the src link in an iframe and hard coding the height.

In some src links it has <div> tags as above.

if there is no <li> tags inside sectabs or  sectabsnew, then I have to reduce the height of the iframe source.

Please tell me how can I do this.

Link to comment
Share on other sites

Correct me if I'am wrong, you wanted the iframe to automatically adjust the height based on the content inside.

 

Please refer to this tutorial:

http://www.mattcutts.com/blog/iframe-height-scrollbar-example/

 

Please note, if the source (src) of the iframe is out of the domain, your auto height adjust will not work as the script could't get the height of the content due to the security restrict of the client browser. ;)

Link to comment
Share on other sites

 

Thanks.

yes, iframe source is out of the domain.

<iframe frameborder=0 border=0 src=”http://abc.com/navigation/74550.cms” name=”childframe” id=”childframe” width=100% >

 

Still the scroll bar appears.

 

In the URL "http://www.mattcutts.com/blog/iframe-height-scrollbar-example/"

 

<script type=”text/javascript”>
// Firefox worked fine. Internet Explorer shows scrollbar because of frameborder
function resizeFrame(f) {
f.style.height = f.contentWindow.document.body.scrollHeight + “px”;
}
</script>

 

how to find the exact height of the src=”http://abc.com/navigation/74550.cms”

Link to comment
Share on other sites

As I said, there is no way to get external source page's height. What you can do is, create a PHP file as a proxy to the external source.

Eg: http://www.yourdomain.com/load_external_source.php

 

In your code:

<?php
if (isset($_GET['url'])) {
$url = urldecode($_GET['url']);
$html = file_get_contents($url);
echo $html;
}
?>

 

So you can query external source using local domain:

http://www.yourdomain.com/load_external_source.php?url=http://abc.com/navigation/74550.cms

With that, the page will be loaded and now your javascript can get the height of the content. Please try out, cheers  :D

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.