Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

window.close() does not work

Hi

Please see my code below and advise why when I click the link the window does not close.

thanks

Hi

The window does not close when I click the link.
Can someone advise how to fix this.

thanks

<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
    </head>
    <body bgcolor="#ffffff" text="#000000">
        <table border="0" cellspacing="0" cellpadding="0" width="765" align="center">
            <tbody>
                <tr>
                    <td colspan="2" style="border-bottom: #999 0px solid; border-left: #999 1px solid; padding-left: 10px; border-top: #999 1px solid; border-right: #999 1px solid">
                    <table border="0" cellspacing="0" cellpadding="0" style="width: 646px; height: 116px">
                       
                    </table>
                    </td>
                </tr>
                <tr>
                    <td valign="top" style="border-bottom: #999 0px solid; border-left: #999 1px solid; padding-bottom: 10px; padding-left: 20px; padding-right: 20px; font-family: Arial, Helvetica, sans-serif; color: #666666; font-size: 16px; border-top: #999 0px solid; font-weight: bold; border-right: #999 1px solid; padding-top: 10px">
                    <p><span style="color: rgb(34,24,22)"><span style="font-family: Verdana" /></span><span style="color: rgb(34,24,22)"><span style="font-family: Verdana"><span style="font-family: Verdana"><span style="color: rgb(34,24,22)"><span style="color: rgb(34,24,22)"><span style="font-family: Verdana"><span style="font-size: smaller"><span style="color: rgb(41,31,22)"><span style="font-family: Verdana">THANKS FOR UPDATING YOUR DETAILS!</span></span></span></span></span></span></span></span></span></p>
                    <p><span style="color: rgb(34,24,22)"><span style="font-family: Verdana"><span style="font-family: Verdana"><span style="color: rgb(34,24,22)"><span style="color: rgb(34,24,22)"><span style="font-family: Verdana"><span style="font-size: smaller"><span style="color: rgb(41,31,22)"><span style="font-family: Verdana">CLICK <a xt="SPCLICK" xthyperlink="441172" xtlinkname="JavaScriptwindowclose" href="JavaScript:window.close()" name="JavaScriptwindowclose">HERE</a>&nbsp;TO CLOSE THIS PAGE.</span></span></span></span></span></span></span></span></span></p>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center" style="border-bottom: #999 1px solid; border-left: #999 1px solid; padding-bottom: 10px; font-family: Arial, Helvetica, sans-serif; color: #666666; font-size: 10px; border-top: #999 0px solid; border-right: #999 1px solid; padding-top: 10px">&nbsp;</td>
                </tr>
                <p>&nbsp;</p>
            </tbody>
        </table>
    </body>
</html>
0
jecommera
Asked:
jecommera
  • 7
  • 4
  • 4
2 Solutions
 
GaryCommented:
href="javascript:window.open('', '_self', '');window.close();"
0
 
jecommeraAuthor Commented:
Sorry I updated the code as below but it makes no difference. When I click the close link nothing happens:

<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
    </head>
    <body bgcolor="#ffffff" text="#000000">
        <table border="0" cellspacing="0" cellpadding="0" width="765" align="center">
            <tbody>
                <tr>
                    <td colspan="2" style="border-bottom: #999 0px solid; border-left: #999 1px solid; padding-left: 10px; border-top: #999 1px solid; border-right: #999 1px solid">
                    <table border="0" cellspacing="0" cellpadding="0" style="width: 646px; height: 116px">
                       
                    </table>
                    </td>
                </tr>
                <tr>
                    <td valign="top" style="border-bottom: #999 0px solid; border-left: #999 1px solid; padding-bottom: 10px; padding-left: 20px; padding-right: 20px; font-family: Arial, Helvetica, sans-serif; color: #666666; font-size: 16px; border-top: #999 0px solid; font-weight: bold; border-right: #999 1px solid; padding-top: 10px">
                    <p><span style="color: rgb(34,24,22)"><span style="font-family: Verdana" /></span><span style="color: rgb(34,24,22)"><span style="font-family: Verdana"><span style="font-family: Verdana"><span style="color: rgb(34,24,22)"><span style="color: rgb(34,24,22)"><span style="font-family: Verdana"><span style="font-size: smaller"><span style="color: rgb(41,31,22)"><span style="font-family: Verdana">THANKS FOR UPDATING YOUR DETAILS!</span></span></span></span></span></span></span></span></span></p>
                    <p><span style="color: rgb(34,24,22)"><span style="font-family: Verdana"><span style="font-family: Verdana"><span style="color: rgb(34,24,22)"><span style="color: rgb(34,24,22)"><span style="font-family: Verdana"><span style="font-size: smaller"><span style="color: rgb(41,31,22)"><span style="font-family: Verdana">CLICK <a xt="SPCLICK" xthyperlink="441172" xtlinkname="JavaScriptwindowclose" href="javascript:window.open('', '_self', '');window.close();" name="JavaScriptwindowclose">HERE</a>&nbsp;TO CLOSE THIS PAGE.</span></span></span></span></span></span></span></span></span></p>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center" style="border-bottom: #999 1px solid; border-left: #999 1px solid; padding-bottom: 10px; font-family: Arial, Helvetica, sans-serif; color: #666666; font-size: 10px; border-top: #999 0px solid; border-right: #999 1px solid; padding-top: 10px">&nbsp;</td>
                </tr>
                <p>&nbsp;</p>
            </tbody>
        </table>
    </body>
</html>
0
 
GaryCommented:
Works for me in IE9, FF, Chrome and Safari
What browser does it not work in?
Something else must be going on.
Check the source of the page and make sure its not a cached copy.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
experts1Commented:
If your code is running in a main window you might get
a confirmation message to close the window.

However, it should close without confirmation if run
in a pop-up (child) window.

So, I would suggest running your updating code in a
pop-up window for seamless closing.
0
 
jecommeraAuthor Commented:
when I click the link, it doesnt respond at all. Used Jquery console to check if errors but none.
0
 
GaryCommented:
What browser?
0
 
jecommeraAuthor Commented:
firefox on mac
0
 
GaryCommented:
Out of my comfort zone, FF has always had problems on the Mac.
If there are no errors then the js is working but FF is not letting the close happen, it can be configured to be overriden in about:config - tho not practical.
It maybe one of those occasions where there is nothing you can do about it and you just have allow for it in the small percentage of people that may be using FF on a Mac.
Have you tried the code in Safari.
0
 
experts1Commented:
Try:
href="JavaScript:function(){window.open('', '_self', '');window.close();}"

Open in new window

0
 
jecommeraAuthor Commented:
I get an error SyntaxError: function statement requires a name
[Break On This Error]       

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

in console
0
 
GaryCommented:
Cannot be done that way.
Did you try it in Safari - that is if you have it installed...
0
 
experts1Commented:
Please confirm if the window you are attempting
to close is a child or popup window, because you wont
be able to close a main window which you physically
opened, directly with Javascript.
0
 
GaryCommented:
Yes you can, the code I posted does exactly that.
0
 
experts1Commented:
Hi GaryC123,

I tested your code myself and on FF it never did anything
but error console said "Scripts may not close windows that
were not opened by script", while on IE6 it prompted for
"Yes / No" confirmation (XP platform).
0
 
GaryCommented:
A prompt is not that much of an inconvenience, I stopped programming for IE6 over 2 years ago.

As for FF, I checked my config and it was enabled for scripts ergo why it was working.
The only option (after researching more) for FF (where it is not a window opened by a script) is to request privileges from the user.
https://developer.mozilla.org/en-US/docs/DOM/window.close?redirectlocale=en-US&redirectslug=window.close
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 7
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now