Forum Moderators: open

Message Too Old, No Replies

Can't make a close window button in Safari 4

Close Button in Safari

         

DouglasMcKibbin

11:07 am on Oct 6, 2009 (gmt 0)

10+ Year Member



I cannot seem to fashion a button to simply close the current window in Safari. I have tried window.close() and self.close(). I have even made a JS function CloseWindow with the window.close() and called it from the button. Nothing works.
How do you close a window in html or JS using a button? My clients will be using IE, Safari, or Firefox.

swa66

12:32 pm on Oct 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



window.close(); works in safari 4.0.3 (mac) for me.

How did you call it ?

DouglasMcKibbin

7:28 pm on Oct 6, 2009 (gmt 0)

10+ Year Member



With the following JS function. The call is at the bottom of the html code.

<head>
<script type="text/javascript">
function CloseWindow()
{
window.close();
}
</script>
</head>
<P>
<form method="POST" action="http://example.net/action.php">
<LABEL for=Name" Style="color:white">Full Name: </LABEL>
<INPUT name=personal_Name type="text" style="color: black ; font-size : 12pt ; font-weight : bold" size="30" tabindex="1"><BR>
<LABEL for=Birthdate" Style="color:white ">Birthdate:: </LABEL>
<INPUT name=personal_Birthdate type="text" style="color: black ; font-size : 12pt ; font-weight : bold" tabindex="2"><BR>
<LABEL for=eMail" Style="color:white ">eMail:: </LABEL>
<INPUT name=personal_eMail type="text" style="color: black ; font-size : 12pt ; font-weight : bold" tabindex="2"><BR><BR>
<LEGEND><LABEL for=Comments or Message Style="color:white"> Comments or Message</LABEL>Comments or Message</LEGEND>
<TEXTAREA name=Comment style="color: black; font-size:12pt; font-weight: bold; font-family: Helvetica" rows="16" cols="62" tabindex="38">
</TEXTAREA>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<BR><INPUT type="submit" value="Submit Form"> <INPUT type="reset"><INPUT type="button" value="Close" onclick="CloseWindow()"><BR><BR>
</P>
</Form>

[edited by: tedster at 8:03 pm (utc) on Oct. 6, 2009]
[edit reason] make the form action an example url [/edit]

rocknbil

4:36 pm on Oct 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard DouglasMcKibbin, this question is probably trivial but just to make sure: this is a window opened FROM the main window, as in a "pop up" window, correct?

Most browsers won't let you close a "main" window. Usually they give you an error alert first.

The only thing I see is the paragraph tag around the form, which I believe is invalid HTML (could be wrong there.) Use <p>&nbsp;</p> above and below the form instead; validate the page [validator.w3.org], make sure it's not some html coding error causing a problem.

DouglasMcKibbin

6:17 pm on Oct 7, 2009 (gmt 0)

10+ Year Member



OK rocknbil I think you are on to something. What exactly constitutes a "main" window? The window I wish to close is a separate page reached only by an <a href tag on what I would think to be a "main" page as...

<a href="http://www.example.org/Site/Financial_AgreementNP.html" target=" blank">

Perhaps I have the wrong understanding of architecture here, and maybe that's why what should work, doesn't work. The page is not a popup window? should I make it a popup? If so, how?

Thanks
Doug

[edited by: tedster at 8:15 pm (utc) on Oct. 7, 2009]
[edit reason] no personal urls, please [/edit]

rocknbil

9:25 pm on Oct 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To reiterate what's discussed in private message - "main" (parent) is the initial window opened by a browser or any tab opened by a direct link or user action (open new tab.) A child window would be any window opened by target="_blank" or target="some-id", or a window initiated by Javascript window.open, initiated from any link in the main window.

Some experiments via PM have indicated window.close() is working on any of these child windows, so it has to be something else . . . .