/    Sign up×
Community /Pin to ProfileBookmark

Close HTML page using a button

I am neither an HTML or Javascript programmer. I create HTML pages by using reference material and researching Web sites, such as this Forum.
What I want to do is “Close” an HTML page by clicking a button, labeled “Exit”, placed within the page. It would take the place of clicking the “X” Close Icon in the upper right hand corner of the page. I have tried using the following HTML code:

<INPUT type=”button” value=”Exit!” onclick=”window.close()”>

This code works fine with Internet Explorer but does not work with Netscape or Mozilla Firefox. Can anyone help me with a code, be it HTML, javascript XML etc., that will close the HTML page, reguardless of which of the 3 browsers are used? Thanks Richard

Mystery solved. Thanks to Jona for providing:

“The code will work in Firefox only if a script opens the new window. You cannot use JavaScript to close a window unless that window was opened by JavaScript. This is usually the case with Internet Explorer as well, only IE displays an alert message. If you want to close the current window, you must open it with JavaScript as well.”

to post a comment
HTML

3 Comments(s)

Copy linkTweet thisAlerts:
@JonaMar 07.2005 — [font=trebuchet ms]Works for me in Firefox...[/font]
Copy linkTweet thisAlerts:
@felgallMar 07.2005 — Form fields need to be contained in forms. Try

<FORM action="window.close()"><INPUT type="submit" value="Exit!" ></FORM>
Copy linkTweet thisAlerts:
@JonaMar 07.2005 — [i]Originally posted by felgall [/i]

[B]Form fields need to be contained in forms. Try



<FORM action="window.close()"><INPUT type="submit" value="Exit!" ></FORM> [/B]
[/QUOTE]


[font=trebuchet ms]I doubt that putting it within a form will make any difference. Besides, you didn't even use valid HTML. Why use the FORM tag at all, since there is no action? You can't have a JavaScript action without the "j&#97;vascript:" protocol, which I do [i]not[/i] recommend since it will not work for users without JavaScript.[/font]
×

Success!

Help @rtourino spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...