Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    San Francisco
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unable to prevent image reload

    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 scrollbars are the real problem.)

    Is this true? Any suggestions to avoid page reload?

    Specifically, I have random images and the one dispalyed is lost upon window resize. If I use a reload, a new image is placed because of the random generator doing its job. However, on a resize I want to keep the same image displayed, maybe by avoiding a reload?

    I have tried cookies and also frames but it's still a problem.

    Any help appreciated!

  • #2
    New Coder
    Join Date
    Jun 2002
    Location
    yorkshire, uk
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    zazen,
    you really should stick in the same thread unless your issue changes a lot. for other readers, the original thread is at:

    http://www.codingforums.com/showthre...&threadid=2286

    have you tried using location.search?
    put this in your <head>, after you have loaded the picture arrays (topPic and botPic).

    Code:
    <script language=javascript>
    window.onresize = "window.location.reload()"
    imgCt = topPic.length
    if (window.location.search) {
      randomNum = window.location.search.substr(1)
      //gets randomNum from URL bar.
    }
    else
      randomNum = Math.floor (Math.random() * imgCt)
      window.location.search="?" + randomNum
      //automatically reloads once and puts randomNum in URL bar
    }
    document.topPicture.src = topPic[randomNum]
    document.botPicture.src = botPic[randomNum]
    </script>
    any luck?
    neil.c

  • #3
    New Coder
    Join Date
    Jul 2002
    Location
    San Francisco
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    still has problems

    Tried it and the images don't appear at all. Even modifications don't work.

    Thanks Neil and everyone who replied, but it just seems impossible.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Code:
    <html>
    <head>
    <title>untitled</title>
    <script type="text/javascript">
    
    var img_dir = 'http://www.noeticart.com/clipart/';
    var randImg = new Array();
    randImg[0] = 'lampc.gif';
    randImg[1] = 'paintcanc.gif';
    randImg[2] = 'tellyc.gif';
    randImg[3] = 'mailboxc.gif';
    randImg[4] = 'plantc.gif';
    
    var whichImg = randImg[Math.floor(Math.random() * randImg.length)];
    
    var imgHTML = (location.search) ?
    '<img src="' + img_dir + unescape(location.search.substring(1)) + '">' :
    '<img src="' + img_dir + whichImg + '">';
    
    if (document.layers) {
    origWidth = innerWidth;
    origHeight = innerHeight;
    onresize = function() {
    if (innerWidth != origWidth || innerHeight != origHeight)
    (location.href.indexOf('?') == -1) ? 
    location += '?' + whichImg : location.reload();
    }
    }
    
    </script>
    </head>
    <body>
    <script type="text/javascript">
    if (document.layers) document.write('<layer left="30%" top="20%">'+imgHTML+'</layer>');
    else document.write('<div style="position:absolute;left:30%;top:20%;">'+imgHTML+'</div>');
    </script> 
    </body>
    </html>
    just a note: this -

    window.onresize = "window.location.reload()"

    ..is incorrect syntax.

    onresize = function() {
    window.location.reload();
    }
    Last edited by adios; 07-23-2002 at 02:53 AM.

  • #5
    New Coder
    Join Date
    Jul 2002
    Location
    San Francisco
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up a geek to the bitter end

    Thanks, Adi, but after trying and modifying a while it produces no image or says "undefined".

    I'm sure the code works when integrated with my page eventually, and appreciate your help. It's just beyond my coding abilities at the moment. I'll keep at it, and eventually will master all.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Works here. *Simple script*.

    I'm guessing 'layers' - but just guessing.

  • #7
    New Coder
    Join Date
    Jun 2002
    Location
    yorkshire, uk
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    zazen,

    why don't you stick your whole page up here - in an attachment if its very big. this problem is getting quite frustrating for me cos whenever i test anything - it works!

    it must be the way you're integrating the scripts we're suggesting into your page, cos on their own they usually work fine.

    post your html page (or email it me nc@flashmail.com if you don't want it open on this forum), then i (and others) can try and find out what the problem really is.
    neil.c


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •