开发者

JavaScript close tab after window.open()

开发者 https://www.devze.com 2023-02-13 06:05 出处:网络
I\'ve got a page which open a new window fullscreen but it still has the other page (the one which re-directs) behind so when you close the new window you are taken back to a blank page.

I've got a page which open a new window fullscreen but it still has the other page (the one which re-directs) behind so when you close the new window you are taken back to a blank page.

Is there a way to open a new window and then close the tab which is now inactive?

Currently I have some javascript li开发者_JAVA技巧ke this

window.open("http://website.co.uk");

Thanks


You can technically use window.close() on the opening tab, but browsers usually will not allow JavaScript to close windows that it has not opened. Can you redirect to some useful page that the user can use once they have closed the window?


If you can add some JavaScript code to the page being opened, I think you can use window.opener.close() to close the original window. I tested it in IE8, the browser will ask for confirm before close the original window.

0

精彩评论

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