2014-05-02 27 views
-2

我正在尝试制作幻灯片的照片并将它们发送到另一个窗口。但是在选择图像并按下按钮显示幻灯片后,没有任何反应。我使用萤火虫来检测错误,以及何时出错。但我没有从萤火虫得到任何错误,所以我得问问你们。这是我的代码。 var infoBox; var formTag; var imgUrlList; var imgTextList; var windVar; var urlList; var textList;发送图片到新窗口

function init() { 
     var i; 
     infoBox = document.getElementsByClassName("outerBox"); 
     for (i=0; i<infoBox.length; i++) { 
      infoBox[i].onmouseover = showInfoBox; 
      infoBox[i].onmouseout = hideInfoBox; 
     } 
     formTag = document.getElementsByTagName("input"); 
     for (i=0; i<formTag.length; i++) { 
      formTag[i].onclick = checkedBox; 
     } 

     windVar = null; 
     imgTextList = []; 
     imgUrlList = []; 
    } 
    window.onload = init; 

    function showInfoBox() { 
     var showInfo; 
     showInfo = this.getElementsByClassName("innerBox")[0]; 
     showInfo.style.visibility = "visible"; 
    } 

    function hideInfoBox() { 
     var hideInfo; 
     hideInfo = this.getElementsByClassName("innerBox")[0]; 
     hideInfo.style.visibility = "hidden"; 
    } 

    function checkedBox() { 
     var ImgNode, ImgTag; 
     for (i=0; i<formTag.length; i++) { 
      imgNode = this.parentNode.parentNode.firstChild; 
      imgTag = imgNode.nextSibling 
      if (this.checked) { 
       imgTag.className = "markedImg"; 
      } 
      else { 
       imgTag.className = "unmarkedImg"; 
      } 
     } 
    } 
    function slideShowBtn() { 
     var url, i, filename; 
     imgUrlList.length = 0; 
     imgTextList.length = 0; 
     for (i=0; i<formTag.length; i++) { 
      if (formTag.checked) { 
       url = infoBox.firstChild.getElementsByTagName("img")[i].src; 
       filename = infoBox.firstChild.getElementsByTagName("span")[i].src; 
        imgUrlList.push(url); 
        imgTextList.push(filename); 
      } 
      else break; 
     } 
     newWindow(700,600,"slideshow.htm"); 
    } 

    function newWindow(width,height,fileName) { 
     var windProporties; 
     windProporties = "top=100, left=100,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + width + ",height=" + height; 
     if (windVar != null) if (windVar.closed == false) windVar.close(); 
     windVar = window.open(fileName,"bildspel",windProporties); 
    } 

formTag variabel来自checkbox-input-tag。这是因为我决定选择哪些图片并将其移至新页面。 ImgTextList和imgUrlList是全局变量,它们也会在下一个窗口中显示。 infoBox是一个对称为OuterBox的div类的引用,它内部是另一个名为innerBox的div类,它位于img和span-tags所在的innerBox classdiv中。幻灯片的代码已经写好,我只是写代码发送变量给它。

编辑:我应该有点更多的信息。但是,这里是window.opener所在的幻灯片部分的代码。我已经添加了上面的所有剩余代码。你如何嵌入文件?

// JavaScript for the slideshow page 

    // ----- Global variables ----- 
    var imgUrlList = window.opener.imgUrlList; // Array with filenames of selected images. Initialized to an empty array. 
    var imgTextList = window.opener.imgTextList; // Array with image texts of selected images. Initialized to an empty array. 
    var slideshowMenu = null; // Reference to the image menu. 
    var slideshowImg = null; // Reference to the slideshow img tag. 
    var slideshowText = null; // Reference to the tag for the image text. 

    // ---- Create the image menu and show the first image. Also attach event handlers. ---- 
    function initSlideshow() { 
// Create a image list from the content of the variable imgUrlList 
     var HTMLcode = "<select id='imgMenu'>"; 
     for (var i=0; i<imgTextList.length; i++) { 
      HTMLcode += "<option>" + imgTextList[i] + "</option>"; 
     } // End for 
     HTMLcode += "</select>"; 
     document.getElementById("iMenu").innerHTML = HTMLcode; // Add the select and option tags to the HTML code 
     slideshowMenu = document.getElementById("imgMenu"); // Save a reference to the menu's select tag 
     slideshowMenu.selectedIndex = 0; // Select the first option in the menu 
     slideshowImg = document.getElementById("slideshowBox").getElementsByTagName("img")[0]; 
     slideshowText = document.getElementById("slideshowBox").getElementsByTagName("div")[0]; 
     // Show the first image 
     slideshowImg.src = imgUrlList[0]; 
     slideshowText.innerHTML = imgTextList[0]; 
     // Attach event handlers 
     var slideshowButtons = document.getElementById("slideshowForm").getElementsByTagName("input"); 
     slideshowButtons[0].onclick = showPrevImage; 
     slideshowButtons[1].onclick = showNextImage; 
     slideshowMenu.onchange = showSelectedImage; 
    } // End initSlideshow 
    window.onload = initSlideshow; 

    // ---- Show previous image in the list (menu) ---- 
    function showPrevImage() { 
     var ix = slideshowMenu.selectedIndex; // Index for the current image 
     if (ix > 0) { // If it's not already the first image 
      slideshowMenu.selectedIndex = ix-1; 
      slideshowImg.src = imgUrlList[ix-1]; 
      slideshowText.innerHTML = imgTextList[ix-1]; 
     } 
    } // End showPrevImage 

    // ---- Show next image in the list (menu) ---- 
    function showNextImage() { 
     var ix = slideshowMenu.selectedIndex; // Index for the current image 
     if (ix < slideshowMenu.length-1) { // If it's not already the last image 
      slideshowMenu.selectedIndex = ix+1; 
      slideshowImg.src = imgUrlList[ix+1]; 
      slideshowText.innerHTML = imgTextList[ix+1]; 
     } 
    } // End showNextImage 

    // ---- Show selected image in the list (menu) ---- 
    function showSelectedImage() { 
     var ix = slideshowMenu.selectedIndex; // Index for the selected image 
     slideshowImg.src = imgUrlList[ix]; 
     slideshowText.innerHTML = imgTextList[ix]; 
    } // End showSelectedImage 
+0

缩小范围。什么是最简单的版本仍然有效? – Anko

+0

你需要更接近错误。而且,这只是所有代码的一部分,很难找到像这样的错误... – Gustavo

回答

0

恩,你从来不会做任何事情发送它。将它作为查询字符串参数传递,或者让子代在开叫器中引用全局变量。

var foo = window.opener.imgUrlList;