Create a close button on a website?

Hello, I would like to know how to create a link that, when clicked, closes the current page. I am using FrontPage 2002. Thank you in advance!!!

21 answers

  1. Contributor
    Hi everyone,
    Personally, I would put:
    <input type='button' value='Close' onClick='self.close()' name="button">
    It's JavaScript. In fact, it's a button, not very aesthetic, I agree because it's gray, but somewhere in CCM, there's a post that talks about the possible modifications to the color and plenty of fully customizable options for buttons in JavaScript.
    In any case, give it a try and let us know what you think...
    Important: this code should be inserted exactly where you want your page to close.

    http://abarka.free.fr
    When the syntax is right, EVERYTHING is right; -))
    6
    1. Hello everyone.

      If you find the Close button ugly (and I agree).
      Well, as ipl said, you can put an image or you can modify the style of the button:

      In head:

      <style> .button { BORDER: #1473c0 1px solid; FONT-WEIGHT: normal; FONT-SIZE: 10px; COLOR: #1473c0; FONT-FAMILY: verdana; BACKGROUND-COLOR: #FFFFFF; } </style>


      In body:

      <input class="button" type="button" value="Close" />


      For jp.bond,
      In Firefox, in order to close a window via JavaScript, it must have been opened by JavaScript.

      See Firefox JavaScript Console: "Scripts cannot close a window that was not opened by a script."

      To open a window, it's:

      window.open('mypage.htm','mypagename','options');

      Here are the options if you're interested:
      option description
      directory = yes/no Displays navigation buttons or not
      location = yes/no Displays the address bar or not
      menubar = yes/no Displays the menu bar (file, edit, ...) or not
      resizable = yes/no Defines whether the window size is adjustable or not
      scrollbars = yes/no Displays scrollbars or not
      status = yes/no Displays the status bar or not
      toolbar = yes/no Displays the toolbar or not
      width = width (in pixels) Defines the width
      height = height (in pixels) Defines the height

      The options must be entered one after the other, separated by commas, without spaces.

      There you go :)
      3
      1. Security Contributor
        Good evening ElZorro, good evening everyone,

        It depends if it's the main page or an additional window:

        try window.close()
        (adapt this to what you are doing: a button, a link-href, a link-onClick, etc.)

        @12C4 ... In medio stat virtus ...
        Ipl
        1
        1. Contributor
          Hello ElZorro (the fox in Spanish)
          Here's what I use on my pages: this system has the main advantage of returning to the previously opened page by the user (it's the equivalent of the back arrow in Internet Explorer) but also a drawback: if the user has disabled JavaScript in Internet Explorer, I believe it won't work.
          <strong><a href="Javascript:history.go(-1)">myLink</a>

          http://abarka.free.fr
          When the syntax works, EVERYTHING works ;-))
          1
          1. For your information, this code:
            <input type='button' value='Close' onClick='self.close()' name="button">
            or
            <input type='button' value='Close' onClick='window.close();' name="button">

            does not work in Firefox... oops!

            any idea?
            thank you...
            1
            1. I will try. In fact, I made a page with links that, when you click on them, open new windows, and it's to close these new windows that I want to add a button that closes the page when clicked.
              0
              1. So in that case, window.close() should work.

                Kalamit,
                At night, all cats are gray. Not the chickens! :@)
                0
            2. But where do we need to put windows.close()??? If I put it in the html link it doesn't work (which is kind of normal).
              0
              1. Security Contributor
                Good evening ElZorro, good evening everyone,

                In my post, I said to you:
                >adapt this to what you do: a button, a link-href, a link-
                >onClick, etc.)
                - What txiki indicates (Input method and button) works very well!
                - If you prefer a text-link-href, you will code: <a href="javascript:window.close();">Close</a>
                - If you prefer an image-link-href, you will code: <a href="javascript:window.close();"><img src=image.gif border=0 width=20, height=15></a>
                - If you prefer a text-link-onClick, you will code: <a href="#" onClick="window.close();">Close</a>
                - etc.

                Also, to complement txiki's writings, know that you can replace the gray button from the INPUT method with an image of your choice.

                @12C4 ... In medio stat virtus ...
                Ipl
                0
                1. Contributor
                  Hi everyone,
                  I didn't mention the text link because he wanted a button and besides, I wasn't very sure about the exact syntax.
                  If you prefer a text-link-onClick, you would code: <a href="#" onClick="window.close();">Close</a>
                  Thanks ipl for your additional comments (if I may say so) ;-)) Talk to you later

                  http://abarka.free.fr
                  When the syntax goes well, EVERYTHING goes well ;-))
                  0
                  1. Thank you all, I managed to create an onclick button, but I need to find a way to make it look a bit nicer because right now, it's really ugly (lol).
                    0
                    1. Contributor
                      Hello elzorro and the others,
                      If you use Dreamweaver, you can insert a Flash element and in the window that opens, you can choose a button style. There are some really good ones in the basic installation, at least in mine.
                      See you later

                      http://abarka.free.fr 
                      When the syntax is good, EVERYTHING is good ;-))
                      0
                      1. Security Contributor
                        Good evening ElZorro, Txiki, good evening everyone,

                        You can put the image of your choice to replace the ugly button!

                        <input type="image" src="CCM.gif" onMouseOver="..." onMouseOut="...'" onClick="..." width=w height=h>

                        @12C4 ... In medio stat virtus ...
                        Ipl
                        0
                        1. All simple:

                          <a href="#" onClick="window.close();"> <input type="submit" name="Submit" value="Close this window"> </a>

                          Button that can also accept effects with CSS...
                          0
                          1. Hello,

                            I have the same problem and I don't quite understand you. I must say that I am not an expert.

                            I work with Dreamweaver and I just want a link on the text "Close" that, when clicked, closes the page. Is there a code that works in all browsers (IE6, IE7, Firefox, Opera...)?

                            A big thank you!

                            Joanie
                            P.S. Please be clear, as I'm not good at coding.
                            0
                            1. Contributor
                              Hi joanie22,
                              You put the example below.
                              <a href="javascript:window.close();"> close the page </a>

                              NOTE: you can replace the word "javascript" with # which has the same effect.

                              --

                              Happiness is the only thing that one can give without having it.
                              0
                              1. I MADE A WEBSITE THAT I PUBLISHED BY MISTAKE WHILE IT IS NOT FINISHED I WANT TO CLOSE IT HOW DO I DO TO CLOSE IT?
                                ESPECIALLY SINCE IT IS MADE WITH ".FR.GD" PLEASE ANSWER ME BY EMAIL THANK YOU IN ADVANCE SEE YOU +
                                0
                                1. Hello everyone
                                  I just tried all the codes on this page but it doesn't work with Firefox... (I use Dreamweaver)
                                  Even a simple button that says "close" (like a classic gray button) would be enough for me to close a page.
                                  THANK YOU for your help
                                  0
                                  1. Personally, I would put
                                    <input type="button" value="Close" onclick="jsWindowClose()"/> ;)
                                    0
                                    • 1
                                    • 2