0

just cant figure out how to get the below code to auto adjust the hight, dependant on the path in "src". As i dont want hard code the height as the src path may change. I have tried various js methods, but none seem to work.

<iframe src="C:\" height="200" width="100%"></iframe>

I have done the styles inline, but will be managing all styles in a css file.

Help.

  • please provide as some of your codes so that we can analyze.. – AlexJaa Aug 06 '14 at 15:58
  • Sorry, did add the code, but it got striped out. Will add now. – Stuart Smith Aug 06 '14 at 16:08
  • Code now added, very basic code at that. – Stuart Smith Aug 06 '14 at 16:20
  • why the `src="C:\"`? What are you working for? – AlexJaa Aug 07 '14 at 13:07
  • Work for a service desk and want a webpage to show all our documents, etc, currently, its a manual process to add any new folder or documents, where as if I can get an iframe showing the content of the folder, we wont have to update the htm page. There trouble is the iframe needs to be auto size so it will always show all the folders\files in the folder. Hope that makes sense. – Stuart Smith Aug 07 '14 at 15:07
  • Just tried to add image of what its currently doing, but it wont allow me. – Stuart Smith Aug 07 '14 at 15:11
  • maybe you are looking for this http://stackoverflow.com/questions/9975810/make-iframe-automatically-adjust-height-according-to-the-contents-without-using – AlexJaa Aug 07 '14 at 15:11
  • yeah it won't allow you coz your reputation don't met the required for you to post an image. – AlexJaa Aug 07 '14 at 15:12
  • Already ready that thread and none of the soltions work. Have read some many threads and think the issue might lay with the code not being able to detect the boundries of the, content. – Stuart Smith Aug 07 '14 at 15:27

2 Answers2

1

You need to use JavaScript to adjust an iFrame to match the size of the content. Check out this library that will watch to content in the iFrame and keep the size upto date.

https://github.com/davidjbradshaw/iframe-resizer

David Bradshaw
  • 11,859
  • 3
  • 41
  • 70
  • Hi David, I had previously looked at your resizer, but hadnt tried it. Just downloaded it, updated the line in the example\index.html file to c:\ and the content of the c:\ drive is visible, but the window doesnt resize. Am i missing anything? – Stuart Smith Aug 11 '14 at 08:59
1
<script language="javascript" type="text/javascript">
function resizeIframe(obj) {
obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
}
</script>

<iframe  src="http://stackoverflow.com/" frameborder="0" scrolling="no" id="iframe" onload='javascript:resizeIframe(this);' />