Javascript,calling child window function from opener doesn't work

前端 未结 4 1264
南旧
南旧 2020-12-03 11:30

I\'m developing a web application that opens a popup using windows.open(..). I need to call a function on the opened window using the handle returned by \"window.open\", but

4条回答
  •  独厮守ぢ
    2020-12-03 11:58

    The window creation is not a blocking operation; the script continues to execute while that window is opening and loading the HTML & javascript and parsing it.

    If you were to add a link on your original page like this:

    Test
    

    You'd see it works. (I tried it just to be sure.)

    **EDIT **

    Someone else posted a workaround by calling an onload in the target document, here's another approach:

    function AddEmail()
    {
    
            if(addWindow == null) {
            addWindow = window.open("test2.html",null,"height=220px, width=400px, status=no, resizable=no");
            }
    
            if(!addWindow.myRemoteFunction) {
                setTimeout(AddEmail,1000);
            } else { addWindow.myRemoteFunction(); }
    }
    

    This keeps trying to call addWindow.myRemoteFunction every 1 second til it manages to sucessfully call it.

提交回复
热议问题