开发者

Error 'document' is null or not object found when passing value back from child window to parent window

开发者 https://www.devze.com 2023-02-21 05:22 出处:网络
I have tried to use the following code to passing value back from the child window back to the parent window

I have tried to use the following code to passing value back from the child window back to the parent window

      <tr>
        <th class="clLabel">Unit</th>
        <td>
          <asp:TextBox ID="sUnit" runat="server" MaxLength="12" Width="3em" /> 
        </td>
      </tr>


<script type="text/javascript">

    $("#test").click(function () {
        var parent = $(parent.document.body);
        $(parent).find('input#sUnit').val("test");
        window.close();
    });

</script>

But some how error message always display when it's come to this code of line

NOTE: parent page and the child page is holding in the difference host (will this cause the problem?)

Error 'document' is null or not object found when passing value back from child window to parent window

Does anyone know what is it going on? A开发者_如何学运维nd how can I solve it?


Guess this will work.

<script>
$(function (){
     $("#test").click(function () {
        var parent = window.opener.document;
        $(parent).find('input#sUnit').val("test");
        window.close();
    });
})
</script>
<a href="#" id="test">test</a>

UPDATE

the opender Script

<input type="button" onclick="window.open('search.php', '_blank', 'height=200, width=300');" value="launch!" />
<input id="sUnit" value="" type="text"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消