PDA

View Full Version : Javascript Help



skilled1
04-03-2006, 05:49 PM
I recently found a need to have a Javascript auto detect the page height, and width of my iframe i was using on my website.


<script>
document.write('<iframe width="'+(window.innerWidth?window.innerWidth:document.body.clientWidth)+'" height="'+(window.innerHeight?window.innerHeight:document.body.clientHeight)+'" src="report.cfm" name="content"></iframe>');
</script>

Is the code I am using, and it works extremely well, however the problem is not only do i need the script to auto-detect the page height, and width, but i need it to only do so to fill up the remaing space, NOT taken up by the navagation at the top. ie, if the Page Display is 1024x768 then i need the iframe to be 900x768

Anyone see where I can improve my code to not only auto detect the window size, but also factor in that it needs to be 124 pixels smaller than the max window height?

Twey
04-03-2006, 05:52 PM
I don't understand why you need to do this, and can't just use
style="height:100%;width:100%;"

skilled1
04-03-2006, 05:55 PM
<DIV id=content style="Z-INDEX: 1; LEFT: 0px; RIGHT: 0px; WIDTH: 1013px; POSITION: absolute; TOP: 69px; HEIGHT: 546px">


<script>
document.write('<iframe width="'+(window.innerWidth?window.innerWidth:document.body.clientWidth)+'" height="'+(window.innerHeight?window.innerHeight:document.body.clientHeight)+'" src="report.cfm" name="content"></iframe>');
</script>

<!---
<IFRAME src="report.cfm" frameBorder=0 width=100% height=100% name="content">
--->
</DIV>

because i am using it in the following notation.

so to clarify, the DIV is forcing the page to load with those dimentions, ie atleast, 1013px and drop the location of the ifram down 69px from the top so that there is room for the navagation, then i need the iframe to auto ditecto the size of the browser being used, and fix itself to take up the room down below, minus the room at the top [the 69px]

using the 100% by 100% om the origional iframe code [commented out above] only limited it to that as defined in the div

Twey
04-03-2006, 06:27 PM
Using absolute pixel values for everything is a very bad idea. I suggest you rethink your layout using percentage or em values

skilled1
04-03-2006, 06:33 PM
i understand that it is a bad idea, but that is not the fixthat i am currently looking for, i just need help with the code to do exactly what it is already doing - the 69pixels from the top to leave way for the navigation [or rather not add the 69pixels to the bottom of the page making it scroll for no reason]

skilled1
04-03-2006, 08:57 PM
ahhhh i figured it out with help from another forum


<script>
document.write('<iframe width="'+((window.innerWidth?window.innerWidth:document.body.clientWidth) -0) +'" height="'+((window.innerHeight?window.innerHeight:document.body.clientHeight) - 69) +'" src="report.cfm" name="content"></iframe>');
</script>

if anyone wants the code please feel free to use it