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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2016
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Random Images are not getting displayed when a popup displays in the same page.

    Hi,

    I am new to this forum. Could you please help me out in fixing this issue. The problem is in my page the images will be getting changed randomly but when i click on a link button a popup window with window.open will navigate a user to another page but in the background the page with random image gets disappeared. Is it possible to make the image appear in the page. Please find the code below. Could you please let me know should i need to add a event listener if so then which event listener will work on click of link button and popup window is being displayed so that the image in the background will be displayed.

    Code:
    var num;
    var temp=0;
    var speed=5000; /* this is set for 5 seconds, edit value to suit requirements */
    var preloads=[];
    
    /* add any number of images here */
    
    preload(
    'Images/Stock/1.jpg',
    'Images/Stock/2.jpg',
    'Images/Stock/3.jpg',
    'Images/Stock/4.jpg',
    'Images/Stock/5.jpg',
    'Images/Stock/6.jpg',
    'Images/Stock/7.jpg',
    'Images/Stock/8.jpg'
    );
    
    function preload(){
    
    for(var c=0;c<arguments.length;c++) {
    preloads[preloads.length]=new Image();
    preloads[preloads.length-1].src=arguments[c];
    }
    }
    
    function rotateImages() {
    num=Math.floor(Math.random()*preloads.length);
    if(num==temp){
    rotateImages();
    }
    else {
        document.getElementById("pagemiddlecenter").style.backgroundImage = 'url(' + preloads[num].src + ')';
    temp=num;
    
    setTimeout(function(){rotateImages()},speed);
    }
    }
    
    if(window.addEventListener){
    window.addEventListener('load',rotateImages,false);
    }
    else { 
    if(window.attachEvent){
    window.attachEvent('onload',rotateImages);
    }
    Thanks,
    Deepak
    Last edited by VIPStephan; 05-14-2016 at 10:09 PM. Reason: added code BB tags

  2. #2
    Senior Coder
    Join Date
    Aug 2010
    Posts
    1,123
    Thanks
    30
    Thanked 250 Times in 248 Posts
    document.getElementById("pagemiddlecenter").style.backgroundImage = 'url(' + preloads[num].src + ')';

    document.getElementById("pagemiddlecenter").style.background = 'url(' + preloads[num].src + ')';


    Welcome to the Forum
    Cleverness is serviceable for
    everything,
    sufficient in nothing.

  3. Users who have thanked DaveyErwin for this post:

    DEEPAK_619 (05-16-2016)


 

Tags for this Thread

Posting Permissions

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