javascript newwindow.document.getElementById有时不';行不通

javascript newwindow.document.getElementById有时不';行不通,javascript,settimeout,getelementbyid,window.open,Javascript,Settimeout,Getelementbyid,Window.open,我正在尝试访问新打开的窗口(window.open)上的元素,然后更改其style.display属性以使其可见。我尝试过不同的版本,但在我最好的版本中,它只在某些时候起作用。它似乎受到正在处理的其他事情的数量的影响,因为当我打开第三个窗口时,它会花费很长时间并且不起作用。有时它甚至不适用于第一个打开的窗口 var poppy=null; function openAlf(anch,id) { poppy=window.open("http://mrsbos.wikisp

我正在尝试访问新打开的窗口(window.open)上的元素,然后更改其style.display属性以使其可见。我尝试过不同的版本,但在我最好的版本中,它只在某些时候起作用。它似乎受到正在处理的其他事情的数量的影响,因为当我打开第三个窗口时,它会花费很长时间并且不起作用。有时它甚至不适用于第一个打开的窗口

    var poppy=null;
    function openAlf(anch,id) {
    poppy=window.open("http://mrsbos.wikispaces.com/Alphabetical+Code+list#"+id,
    "_blank"," width=550, height=600, left=500,top=0");

    setTimeout(showEl,1000);

     }

    function showEl(){

    poppy.document.getElementById('area000t').style.display="block";
    }
在另一个版本中,我将area_id传递给showEl函数。这个函数也不起作用,这很遗憾,因为我需要能够使用openAlf()函数打开不同的元素。我认为这是时间问题。有人知道我能做什么吗


或者有没有一种方法可以从字母页面中读取元素,而不用打开它,然后用window.open和mywindow将它们写入一个新窗口。如果您乐于使用jQuery,您可以在本文中找到一个可能的解决方案:


此解决方案有效

您是否可以尝试在poppy.document.ready事件中致电showEl?此外,请确保您的ID以字母[a-z]开头,并且在网页中是唯一的。如果这3个步骤没有说明问题所在,我不知道。我添加了这个循环是为了确保在更改style属性之前加载元素,但它只适用于opera和IE,而不适用于Chrome和Safari。在最后的2段中,它进入了一个无止境的循环。while(poppy.document.getElementById('area000t')==null){console.log('waiting…');}poppy.document.getElementById('area000t').style.display=“block”;var-poppy=null;函数openAlf(anch,id){poppy=window.open(“,”width=550,height=600,scrollbars=yes,left=500,top=0”);//while(poppy.contentDocument.document.getElementById('are000t')==null){//console.log('waiting…');//$(document.ready(函数(){poppy.document.getElementById('are000t').style.display=“block”;}})我尝试使用jQuery document.ready,但得到了相同的typeError(无法从null读取样式。还有poppy.body.childElements=empty。有人知道为什么以及怎么做吗?
      var poppy=null;




      function openAlf(anch,id) {
        poppy=window.open("http://mrsbos.wikispaces.com/Alphabetical+Code+list",
       "_blank"," width=550, height=600, scrollbars=yes,left=500,top=0");

      readyState=setTimeout(function(){checker(id) },1000);
       }

      function checker(id){
      console.log("checker");
      try{
      console.log("try");

      poppy.document.getElementById(id).style.display="block";
      clearInterval(readyState);
       }

       catch(err){
       console.log("catch");
       readyState=setTimeout(function(){checker(id) },1000);
       }
       }