What do I change so this js doesn't interfere with another?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tpgames
    Contributor
    • Jan 2007
    • 783

    What do I change so this js doesn't interfere with another?

    Code:
    window.onload = initiFrame;
    
    function initiFrame() {
    	for (var i=0; i<document.links.length; i++) {
    		document.links[i].target = "content";
    		document.links[i].onclick = setiFrame;
    	}
    }
    
    function setiFrame() {
    	document.getElementById("content").contentWindow.document.location.href = this.href;
    	return false;
    }
    The above code interferes with the below code. The above won't work at all if I use the below code. The link automatically opens up in a new window instead of in the iframe like its supposed to. The following link is the correct behavior.
    Correct
    Here is the wrong behavior link.
    Wrong

    Code:
    imgName = new Array()
    for (x=1; x<=40; x++) {
    imgName[x] = x
    }
    
    contextPath = "http://i107.photobucket.com/albums/m287/tpkyteroo/ah/";
    extension = ".jpg";
    current = 1;
    
    window.onload = randomizeImage
    
    function randomizeImage() {
    
    changeImg()
    }
    
    
    function changeImg() {
    holder = document.getElementById("bgHolder");
    holder.style.background="url(" + contextPath + imgName[current] + extension + ")";
    
    if (current < imgName.length-1) {	current = current+1 }
    
    else { current = 1 }
    
    setTimeout('randomizeImage()',20000);
    }
    Thanks!
  • tpgames
    Contributor
    • Jan 2007
    • 783

    #2
    Okay, I think the issue is the body.onload = bit. However, what do I do with the
    Code:
    window.onload = randomizeImage
    bit so that it will do that , without it confusing the poor browser? Disabling it, solves the links not loading in to the iframe problem, but then the images don't work at all.
    Thanks!

    Comment

    • DutchKingCobra
      New Member
      • Mar 2007
      • 37

      #3
      hi pal,
      try this

      Code:
      setTimeout('randomizeImage()',100);//only is executed on pageload
      
      function randomizeImage() {
      holder = document.getElementById("bgHolder");
      if (holder==null){
      setTimeout('randomizeImage()',100);}
      else{
      changeImg();
      }
      }
      always works fine for me
      peace

      Comment

      • tpgames
        Contributor
        • Jan 2007
        • 783

        #4
        I've already read quirksmode and don't get it.
        Tried
        Code:
        	<element.onload="initiFrame">

        Comment

        • tpgames
          Contributor
          • Jan 2007
          • 783

          #5
          forgot to refresh page again. will post again after I try your method. it should work.

          Comment

          • tpgames
            Contributor
            • Jan 2007
            • 783

            #6
            Thanks! That works!

            Comment

            • DutchKingCobra
              New Member
              • Mar 2007
              • 37

              #7
              glad i could help m8 :P

              Comment

              Working...