9

Is it possible to close a tab via JavaScript?

For example, I have redirected user from email to my page, then I need to open pop-up window and close the tab I have redirected user to.

Does window.close() work only for windows created with JavaScript? Or is it possible to modify tab, so that becomes a popup window?

1

8 Answers 8

10

window.close() is working only for windows created inside javascript?

window.close should also work for new windows your page has created using target="_blank". Other than that, there is no way to close the current window or tab programmatically. As far as I know, what you want to do - closing an original window that you have not opened - is impossible.

Sign up to request clarification or add additional context in comments.

4 Comments

So basically i'll have empty window opened and user will have to close it manually?
@Beck if you open the window, you should be able to close it. If you didn't open it, you won't.
Yea i got it. I'm talking about link inside mail. User first will click on it, join my website page, then on that page javascript will create new popup window. And initial page user will have to close manually.
@Beck nope, that won't work. The link opened from your E-Mail is outside of your control.
2

No. You can only control child windows created inside a parent window.

"Is it possible to modify tab, so that it's become popup window?" Only if you have access to the page where it is created.

Comments

1

This might be old, but let's answer it.

I use top.close() to close a tab.

window.close() or other open...close didn't work for me.

top.close() works in chrome too.

Comments

0

if the user has configured his browser to open popups as tabs, you will have that behavior.

in other ways i don't think it is possible...

Comments

0

I don't know if I understand:

You send a link via email. The link needs to open a pop-up with your webpage??? If it is that, simply make the emailed link open in a new window... It will save lots of trouble with javascript...

1 Comment

How you will do it? Gmail doesn't allow javascript inside mails.
0

It can be done. Just use:

window.open('', '_parent', '');
window.close();

It is not My solution but I saw it here: http://www.yournewdesigner.com/css-experiments/javascript-window-close-firefox.html

You can also read why it works in the link.

1 Comment

Doesn't work in Firefox 26.. I just tested it in the console.
0

I had the same problem, the solution for one following:

let win = window.open(null, "_self");
win.close();

2 Comments

Please add description
I needed to close the active tab. I tried what the other answers indicated, but they did not work. Then I thought about throwing the current tab into a variable and then closing it. But instead of "location" I tried the "null" and worked.
0

Yes, tab can be closed via script only if opened via script. enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.