popup - Javascript: Close pop up window - Stack Overflow

I have a button on the main page, which will open (window.open()) a window W1 to allow user to select s

I have a button on the main page, which will open (window.open()) a window W1 to allow user to select stuff on it. After that, user press OK button on the W1 to open window W2 (again window.open()). How can i close the W1 after the user press OK?

I have a button on the main page, which will open (window.open()) a window W1 to allow user to select stuff on it. After that, user press OK button on the W1 to open window W2 (again window.open()). How can i close the W1 after the user press OK?

Share Improve this question asked Feb 7, 2012 at 2:33 Thai TranThai Tran 9,9357 gold badges47 silver badges66 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 3

Use the window.close() method with the name of the target window as shown below:

win1 = window.open("","","width=100,height=100");
okBtn.onclick = function() {
    win2 = window.open("","","width=100,height=100");
    win1.close();
}

On the main page you save popup into W1 and define a function that will close W1:

W1 = window.open("","","width=100,height=100");

function closeW1() {
    W1.close();
}

Now on W1 in the same place where you open W2:

okBtn.onclick = function() {
    W2 = window.open("","","width=100,height=100");
    window.opener.closeW1();
}

That's it. You're done.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744355324a4570203.html

相关推荐

  • popup - Javascript: Close pop up window - Stack Overflow

    I have a button on the main page, which will open (window.open()) a window W1 to allow user to select s

    7天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信