难道要循环检查name的值,当不为空时才执行? shi di

解决方案 »

  1.   

    这样如何保证在没有取得返回值时,FF不往下执行???检测后,return false 不行嘛~~
      

  2.   

    我以前就是循环检测的
    javascript:var x=window.open(location.href);var p=setInterval(function(){if (x.document.readyState=='complete'){alert('子窗口加载完毕');clearInterval(p);}},1000);void(0);
      

  3.   

    3楼说的只是检测子窗口是否已经加载完成,但是我希望当用户在子窗口向父窗口设了值以后,父窗口的代码才继续执行。我在父窗口中这样写:
    while( hasvalue == true)
    {
      setTimeout("checkReturnValue()", 1000);
    }
    ...function checkReturnValue()
    {
      if (!document.getElementById("name").value) 
      {
         hasvalue = true
      }
    }hasvalue是个全局变量,初值为false。这样写为什么总是死循环?是不是
    if (!document.getElementById("name").value)
    写得不对?刚接触javascript,不太熟悉,望各位大虾指点。
      

  4.   

    刚才写错了,应该是while (hasvalue == false)
      

  5.   

    解决了。
    var time2;
    function openWindow()
    {
        var left = 0
        var top = 0
      
        if (screen.width > 1024 ) {
           left = (screen.width - 1024)/2
        }
      
        if (screen.height > 960 ) {
           top = (screen.height - 960)/2
        }    newWindow = window.open("getName.htm","_blank","modal=yes, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=400, height=300, left=" + left +", top=" + top +"")    newWindow.focus()    time2 = setInterval("checkReturnValue()", 1000)
    }function checkReturnValue()
    {
      var va = document.getElementById("name");
      if (va.value != "")
      {
          alert(va.value);
          clearInterval(time2);
      }
    }
    ...
    <body>
    <input type="button" onClick="openWindow()" value="弹出">
    <input type="hidden" name="name" id="name" value="">
    </body>