【问题标题】:Closing child window when parent window closes in Jquery在Jquery中关闭父窗口时关闭子窗口
【发布时间】:2012-07-18 14:11:07
【问题描述】:

我有一个窗口,单击按钮可以打开一个窗口。现在我希望在关闭父窗口时关闭子窗口。我为父窗口编写了卸载函数,但是我尝试访问子窗口的代码行引发了错误。

我的子窗口是使用此脚本从后面的代码打开的:

"childWindow=window.open('MyPage.aspx,'ChildWindow','left=20, top=20, height=900, width=500,status= no, resizable= yes, scrollbars=yes, toolbar=no,location=no,menubar=yes'); childWindow.focus();"

在我的父级卸载函数中,我正在这样做:

$(window).unload(function () {
if ($(childWindow) != null)
    $(childWindow).close();});

我想这是我访问子窗口的方式有问题。但是我不知道访问由脚本从后面的代码创建的子窗口的正确方法。

【问题讨论】:

  • Microsoft JScript 运行时错误:'childWindow' 未定义

标签: c# jquery childwindow


【解决方案1】:

您是否在页面 JavaScript 中将 childWindow 声明为全局变量?如果不是,它可能真的未定义到卸载代码。

【讨论】:

    猜你喜欢
    • 2012-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-30
    • 2013-02-14
    • 2011-01-19
    相关资源
    最近更新 更多