Forum Moderators: open

Message Too Old, No Replies

Window resizing

reloading an iframe accordingly

         

Justin_H

11:53 pm on Apr 4, 2004 (gmt 0)

10+ Year Member



I have zero experience with javascript and have spent an hour or so looking around on the net and through the one book i have trying to figure this out to no avail so if someone could help it would be much appreciated

I have an inline frame that needs to be reloaded whenever the window is resized like the user maximizes it or stretches it, something like that. I'm sure it is very simple but i have yet to get it to work mostly because i have never used javascript i'm sure ...

<script language="JavaScript">
window.onResize="What do i put here to reload a frame by name";
</script>

Like i said i have never used js before so i'm sure that even if i nwe what to put in the quotes I probably don't have the thing setup right anyway. Any help would be appreciated

ajkimoto

1:26 pm on Apr 5, 2004 (gmt 0)

10+ Year Member



Justin_H,

This should give you what you need. You have a global event handler for the resize event which calles the resizeFrame() function.

<script type="text/javascript">
<!--
window.onresize=resizeFrame()

function resizeFrame(e){
document.getElementById('myframe').src="mynewpage.htm"
}

//-->
</script>

</head>

<body>
<iframe id="myframe" src="myoriginalpage.htm" style="width:50%">
</body>

Hope this helps,

ajkimoto

Justin_H

4:09 pm on Apr 5, 2004 (gmt 0)

10+ Year Member



That looks like it should do the trick, but in IE 6 it throws an error:
document.getElementById(...) is null or not an object.

you can see my implementation at [anjusevin.com ]

ajkimoto

4:45 pm on Apr 5, 2004 (gmt 0)

10+ Year Member



Justin_H,

Ah. It seems that IE is calling the function as soon as it sees it, but before the rest of the document loads. We need to put a flag in place that flips to true when the doc is loaded:

<script type="text/javascript">
<!--
//initialize global variable flag to false
var funcFlag=false
function resizeFrame(e){
//check to see if funcFlag is true or not
if (funcFlag==true){
document.getElementById("myframe").src="http://www.ebay.com"
}
}

window.onresize=resizeFrame

//-->
</script>

</head>
<!--when doc finished loading, set flag to true//-->
<body onload="funcFlag=true">

That should do it.

ajkimoto

Justin_H

8:31 pm on Apr 5, 2004 (gmt 0)

10+ Year Member



That makes perfect sence, even tried to do something like that myself when i got the error. It still does not work though here is what i have cut and pasted

<html>
<head>
<script type="text/javascript">
<!--
window.onResize=resizeFrame()
//initialize global variable flag to false
var funcFlag=false
function resizeFrame(e)
{
//check to see if funcFlag is true or not
alert("getting there")
if (funcFlag==true)
{
alert("hello")
document.getElementById('secret').src="http://www.anjusevin.com/secret.htm"
document.getElementById('test').src="http://www.amazon.com"
}
}
</script>
</head>
<BODY onLoad="funcFlag=true">
//plain html in here
<iframe id="secret" name="secret" src="http://www.anjusevin.com/secret.htm" height=500 style="width:100%">
<iframe id="test" src="http://www.ebay.com" height=500>
</body></html>

this does not cause any errors, it jsut simply doesn't do anything when you resize the window. most interestingly it pops the "getting there" alert as soon as you navigate to the page. which means the function is called which i don't understand... anyway this newest attempt is still at the address above if you want to see it yourself. Thanks alot for taking the time to help me with this :) also i tried putting an addition window.onResize in the body tag... didn't work obviously

Justin_H

12:54 am on Apr 6, 2004 (gmt 0)

10+ Year Member



thanks very much for the help, finally got it to work just removed the function call from the script in the header and changed the body tag to
<body onResize="resizeFrame()" onLoad="funcFlag=true">