View Full Version : problems keeping variable when page reloads
zazen
07-18-2002, 07:08 PM
Hi,
I need to keep the same image when a page is reloaded due to a browser-window resize. But having trouble figuring out how to combine these two functions into a conditional statement, so that the image variable does not change on reload.
Any help appreciated.
--zz
function reDo() {window.location.reload() }
window.onresize = reDo;
imgCt = topPic.length
function choosePic() {
if (document.images) {
randomNum = Math.floor
((Math.random() * imgCt))
document.topPicture.src = topPic[randomNum]
document.botPicture.src = botPic[randomNum]
}
}
requestcode
07-18-2002, 08:00 PM
With javascript I would think the only way to do it would be using a cookie to store the image name. When the resize function starts you could write the image name out to a cookie do the reload and then in the function that picks the random image you could check if the cookie is available use that instead of the random image. You would then want to delete the cookie after you grabed it so that the next time it would do the same thing all over again.
zazen
07-18-2002, 08:13 PM
Thanks for the suggestion!
However, I believe there is another approch, maybe using old-fashioned html frames? Looking at http://athleta.com as an example, there is no reload of the image, and I don't accept their cookies....
neil.c
07-18-2002, 09:04 PM
you're right. you put your page into a 'false' frameset i.e. have its frame 100% width, then you can send a variable to the frameset page. i'm not sure exactly how, something like this maybe:
frameset.html
<html>
<head>
<title>untitled</title>
<script>
<!--
var picNumber = -1
//-->
</script>
</head>
<body>
<frameset cols=1>
<!--not sure about the above tag-->
<frame name=main width="100%" src="content.html">
</frameset>
</body>
</html>
content.html
<script>
function reDo() {window.location.reload() }
window.onresize = reDo()
imgCt = topPic.length
function choosePic() {
if (document.images){
if (parent.picNumber >= 0) {
randomNum = parent.picNumber
}
else {
randomNum = Math.floor ((Math.random() * imgCt))
parent.picNumber = randomNum
}
document.topPicture.src = topPic[randomNum]
document.botPicture.src = botPic[randomNum]
}
}
</script>
i don't see why this shouldn't work. any luck?:thumbsup:
zazen
07-18-2002, 10:46 PM
The image still reloads on resize. Agggh. Also, NN4 seems to shun the 100% row. Still working on it....
<frameset rows="99%,1%" border="0">
<frame name="frame1" src="index.html">
<frame name="frame1" src="blank.html">
</frameset>
zazen
07-19-2002, 10:43 PM
Still unable to prevent image reload.
I've read that losing dynamic content when resizing NN4 browser is a common problem, and the only way to solve is a page reload. Also read that the real problem are the scrollbars.
Any suggestions to avoid reload?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.