Window.close not working IN CHROME

26,946 views
Skip to first unread message

Gatim Tewari

unread,
Nov 25, 2014, 1:20:27 AM11/25/14
to chromi...@chromium.org
Using any of the below scripts cannot close the current tab in chrome

<script>

function closeMe()
{
var win=window.open("","_self");
win.close();
}
</script>

<html>
<body>
<form>
<input type="button" name="Close"
onclick="closeMe()" />
</form>
</body>
</html>
We can also write script like this
function winClose()
{
window.top.opener=null;
window.close();
}

or

function closeWindow()
{
window.open('','_parent',''); 
window.close();
}

PLEASE ADVISE WHAT CAN BE A RESOLUTION, CHROME GIVES AND ERROR AS "wE CAN CLOSE ONLY THOSE WINDOWS THAT ARE OPENED VIA SCRIPT"

tHANKS
GATIM

Martin Hodgkins

unread,
Nov 25, 2014, 6:58:50 AM11/25/14
to chromi...@chromium.org
If you put the script tag actually inside the html then it works. I have just tried it.
<html>
<head>
<script>

function closeMe()
{
var win=window.open("","_self");
win.close();
}
</script>

</head>
<body>
<form>
<input type="button" name="Close"
onclick="closeMe()" />
</form>
</body> 
</html> 

Robert Brown

unread,
Nov 25, 2014, 7:12:05 AM11/25/14
to chromi...@chromium.org

Hi,

did you get this working?
I have just updated to version 39 and now none of our javascript close functions work.

I have tried many different variations of the windows.close() but Google Chrome just ignores it and the window just stays open.

Many thanks,

Robert

Martin Hodgkins

unread,
Nov 25, 2014, 7:21:01 AM11/25/14
to chromi...@chromium.org
Yes, version 39. I just made a html file with this in it (just moved the script into the head) and it opens in chrome and when the button is clicked the tab closes.
<html>
<head>
<script>

function closeMe()
{
var win=window.open("","_self");
win.close();
}
</script>

</head>
<body>
<form>
<input type="button" name="Close"
onclick="closeMe()" />
</form>
</body> 
</html>

Robert Brown

unread,
Nov 25, 2014, 7:21:44 AM11/25/14
to chromi...@chromium.org

Hi Martin,

have you tested this with version 39 Google Chrome?

regards,

Robert

Robert Brown

unread,
Nov 25, 2014, 7:40:54 AM11/25/14
to chromi...@chromium.org
Thanks,

I will try that now.

Regards,

Robert

Robert Brown

unread,
Nov 25, 2014, 7:46:20 AM11/25/14
to chromi...@chromium.org
Hi Martin,

if I open the new htm page from a parent and then use your code to close the newly opened htm page then nothing happens.


:-(

Gatim Tewari

unread,
Nov 26, 2014, 2:30:41 AM11/26/14
to chromi...@chromium.org
Hi,

I've tested it already with the same type under <html> and <head> in ver 39, none of them work and I am not able to use it like chrome.remove.tabs() function exaclty.

As of now no workarounds working for me

Regards,
~GAtim

Biself Uken

unread,
Dec 25, 2014, 3:36:43 AM12/25/14
to chromi...@chromium.org
I use the latest version of Chrome and copied all of the code, still not working, who can tell me why?

在 2014年11月25日星期二UTC+8下午8时21分01秒,Martin Hodgkins写道:

Jason

unread,
Jan 8, 2015, 10:11:10 AM1/8/15
to chromi...@chromium.org
By chance do any of you have the registry setting that Chrome implemented for having showModalDialog continue to work? You can find details about it here:

I find that if I have this setting enabled, window.close() and all variations do not work. However if I remove it, they all work as they should.

Can anyone else confirm this?

liju liju

unread,
May 12, 2015, 8:26:09 AM5/12/15
to chromi...@chromium.org, fir...@gmail.com
Martin Absconding :)
 

ganesh paiya

unread,
Oct 27, 2016, 1:36:27 AM10/27/16
to Chromium-Apps-Announce, fir...@gmail.com, ganesh paiya


 ScriptManager.RegisterStartupScript(Me, Me.GetType(), "Close_Window", "self.close();", True)
        ScriptManager.RegisterStartupScript(Me, Me.GetType(), "callJSFunction", "closeWindow();", True)
        ScriptManager.RegisterStartupScript(Me, Page.GetType, "ClosePage", "window.open('window.close();', '_self', null)", True)
how to call a asp.netwebservicenandroidusingphonegap.txt

Eyob Zeleke

unread,
Oct 27, 2016, 8:23:43 AM10/27/16
to ganesh paiya, Chromium-Apps-Announce, fir...@gmail.com
Thanks Ganesh. I have tried these before and none of them work in Chrome. These work in IE, Edge and also Firefox (with a setting change) but not chrome. Do you have any other suggestion?


--
You received this message because you are subscribed to the Google Groups "Chromium-Apps-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-app...@chromium.org.
To post to this group, send email to chromi...@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-apps/.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.


PhistucK

unread,
Oct 27, 2016, 9:18:56 AM10/27/16
to Eyob Zeleke, ganesh paiya, Chromium-Apps-Announce, fir...@gmail.com
Are you trying to close a window/tab that was not opened by a script? If so, that will not work, by design.


PhistucK

On Thu, Oct 27, 2016 at 3:18 PM, 'Eyob Zeleke' via Chromium-Apps-Announce <chromi...@chromium.org> wrote:
Thanks Ganesh. I have tried these before and none of them work in Chrome. These work in IE, Edge and also Firefox (with a setting change) but not chrome. Do you have any other suggestion?
On Thursday, October 27, 2016 1:36 AM, ganesh paiya <tech...@gmail.com> wrote:




 ScriptManager.RegisterStartupScript(Me, Me.GetType(), "Close_Window", "self.close();", True)
        ScriptManager.RegisterStartupScript(Me, Me.GetType(), "callJSFunction", "closeWindow();", True)
        ScriptManager.RegisterStartupScript(Me, Page.GetType, "ClosePage", "window.open('window.close();', '_self', null)", True)
--
You received this message because you are subscribed to the Google Groups "Chromium-Apps-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-apps+unsubscribe@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium-Apps-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-apps+unsubscribe@chromium.org.

Eyob Zeleke

unread,
Oct 27, 2016, 9:30:17 AM10/27/16
to PhistucK, ganesh paiya, Chromium-Apps-Announce, fir...@gmail.com
Yes, I am trying to close a window that was not opened by a script. Is there any other way at all?
So, I have an a website (c#) that uses windows authentication. What I am trying to do is, add a Button (Logout) and kill the windows authentication session upon clicking the button. I was thinking of just using javascript to do it but isn't working for chrome browsers like we discussed. Any other suggestions?

On Thursday, October 27, 2016 9:18 AM, PhistucK <phis...@gmail.com> wrote:


Are you trying to close a window/tab that was not opened by a script? If so, that will not work, by design.


PhistucK

On Thu, Oct 27, 2016 at 3:18 PM, 'Eyob Zeleke' via Chromium-Apps-Announce <chromi...@chromium.org> wrote:
Thanks Ganesh. I have tried these before and none of them work in Chrome. These work in IE, Edge and also Firefox (with a setting change) but not chrome. Do you have any other suggestion?
On Thursday, October 27, 2016 1:36 AM, ganesh paiya <tech...@gmail.com> wrote:




 ScriptManager. RegisterStartupScript(Me, Me.GetType(), "Close_Window", "self.close();", True)
        ScriptManager. RegisterStartupScript(Me, Me.GetType(), "callJSFunction", "closeWindow();", True)
        ScriptManager. RegisterStartupScript(Me, Page.GetType, "ClosePage", "window.open('window.close();' , '_self', null)", True)
--
You received this message because you are subscribed to the Google Groups "Chromium-Apps-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-apps+unsubscribe@ chromium.org.
To post to this group, send email to chromi...@chromium.org.
Visit this group at https://groups.google.com/a/ chromium.org/group/chromium- apps/.
For more options, visit https://groups.google.com/a/ chromium.org/d/optout.
--
You received this message because you are subscribed to the Google Groups "Chromium-Apps-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-apps+unsubscribe@ chromium.org.
To post to this group, send email to chromi...@chromium.org.
Visit this group at https://groups.google.com/a/ chromium.org/group/chromium- apps/.
For more options, visit https://groups.google.com/a/ chromium.org/d/optout.
--
You received this message because you are subscribed to the Google Groups "Chromium-Apps-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-app...@chromium.org.

PhistucK

unread,
Oct 27, 2016, 9:33:07 AM10/27/16
to Eyob Zeleke, ganesh paiya, Chromium-Apps-Announce, fir...@gmail.com
​Not really, you cannot close those windows.
You can communicate with them using localStorage and the storage event, or using BroadcastChannel and make them navigate to about:blank, or to a page that explains that the season is over or something like that.​


PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-apps+unsubscribe@chromium.org.

Eyob Zeleke

unread,
Oct 27, 2016, 10:36:43 AM10/27/16
to PhistucK, ganesh paiya, Chromium-Apps-Announce, fir...@gmail.com
ok, thanks for your help!


To unsubscribe from this group and stop receiving emails from it, send an email to chromium-app...@chromium.org.
Reply all
Reply to author
Forward
0 new messages