Somebody
Somebody

Reputation: 9645

Javascript - closing tab

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?

Upvotes: 9

Views: 14893

Answers (8)

D.Waasala
D.Waasala

Reputation: 155

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

Upvotes: 0

Cleverson Ruas
Cleverson Ruas

Reputation: 1

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

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

Upvotes: 0

Soley
Soley

Reputation: 1776

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.

Upvotes: 1

CovexLy
CovexLy

Reputation: 1

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.

Upvotes: 0

SoulWanderer
SoulWanderer

Reputation: 305

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...

Upvotes: 0

Mads Mogenshøj
Mads Mogenshøj

Reputation: 2068

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.

Upvotes: 2

helle
helle

Reputation: 11650

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...

Upvotes: 0

Pekka
Pekka

Reputation: 449435

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.

Upvotes: 10

Related Questions