Skip navigation
Currently Being Moderated

Close your buttons

Nov 17, 2012 12:11 AM

Howdy,

 

I'd like to add a button to a page that, when clicked, will close that page.  This sounds simple, but it's over my head.

 

Can you make some suggestions as to how to do this?  I'm a novice, so all detail is appreciated.

 

I'm using CS3, believe it or not.  Still works great.

 

Thanks,

 

CS

 
Replies
  • Currently Being Moderated
    Nov 17, 2012 12:43 AM   in reply to Crellin Sound

    And what page do you want to "close"? All you can do is close tabs/ or windows or forward the user to another page, the methods for which a simple web search can bring up. If you need something else, you need to explain better.

     

    Mylenium

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 17, 2012 1:33 AM   in reply to Crellin Sound

    In principle, it is simple. This is all you need:

     

    <button onClick="window.close()">Close</button>

     

    In practice, it's not so simple. Browsers will normally close a page only if the page has been opened using JavaScript.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 17, 2012 6:25 AM   in reply to Crellin Sound

    Use Dreamweaver's built-in Open Browser Window behavior.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 17, 2012 10:42 AM   in reply to Crellin Sound

    Making Pop-up Windows in Dreamweaver (Behaviors Panel)

    http://alt-web.blogspot.com/2012/03/create-pop-up-window-in-dreamweave r.html

     

     

    Nancy O.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 21, 2012 7:38 AM   in reply to Crellin Sound

    What form script do you currently use on your site? Is there documentation explaining a "redirect" or "thank-you" page?

     

    Any decent script will give you both a fail prompt/page and success page redirect. It sounds like your form has a fail prompt. If you are using a prebuilt form processing script, it should have something built in to redirect you to a success or thank you page, this will be done within the form or script and won't require the javascript you inquired about above.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 21, 2012 10:04 AM   in reply to Crellin Sound

    Maybe I don't need the Open Browser Window after all.

    The form field validation & redirect to success or error pages should be built into the form processing script. You shouldn't need behaviors to open a new window on submit.

     

     

    Nancy O.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 23, 2012 6:37 AM   in reply to Crellin Sound

    You can try this -

     

    <button onclick="self.close();">Close</button>

     

    or this -

     

    <p><a href="#" onclick="self.close();">Close</a></p>

     

    (there is no need to put anything inside the parens - for this effect they would just stay empty)

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 24, 2012 3:24 AM   in reply to Crellin Sound

    As I said right at the outset, browsers will normally allow JavaScript to close a page only if the page was originally opened using JavaScript. What you're now doing is submitting the form, and using PHP to redirect the user to a new page if the form is successfully submitted. In other words, the success page is not opened using JavaScript. That's why Safari, Chrome, and Firefox resolutely refuse to close the page. It's a security measure against malicious scripts. In your case, it's not malicious. But the browser has no way of knowing, so it refuses to execute the code.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 24, 2012 6:12 AM   in reply to Crellin Sound

    Crellin Sound wrote:

     

    How do I get around this? 

    You don't. What is the point of closing the browser window or tab after someone has submitted a form? If the form had opened another window, there might be a reason to do it. But in your case, the user is simply taken to another page in the same window/tab.

     

    The sort of circumstances where you might want to close the window are when you're asking the user to agree to terms and conditions, or when you're displaying a map of how to get somewhere. It's common to open terms and conditions or maps in a separate window to allow the user to view them alongside the main page. Adding a close button makes it easier to close the window when it's no longer needed.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 24, 2012 8:36 AM   in reply to Crellin Sound

    You can't do it that way. You could use a PHP session to capture the URL of the page from which the contact page was accessed, and then use that to redirect the user back to the original page. Instead of using HTML pages for your contact and success pages, you would need to make them PHP pages. Also, open the contact page in the same window rather than a new one

     

    At the top of the contact page, you would capture the referring URL and store it like this:

     

    <?php

    session_start();

    if (isset($_SERVER['HTTP_REFERER'])) {

        $_SESSION['ref'] = $_SERVER['HTTP_REFERER'];

    } else {

        $_SESSION['ref'] = 'http://www.crelinsound.com/';

    }

    ?>

     

    In the success page, you would need to add this:

     

    <?php

    session_start();

    if (isset($_SESSION['ref'])) {

        $ref = $_SESSION['ref'];

    } else {

        $ref = 'http://www.crelinsound.com/';

    }

    $_SESSION = array();

    session_destroy();

    ?>

     

    Instead of the close button, create a link back to the original page.

     

    <a href="<?php echo $ref; ?>">Return to the site</a>

     

    Message was edited by: David_Powers to correct last sentence of the first paragraph. The contact page must be opened in the same window, not a new one.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 25, 2012 6:50 AM   in reply to Crellin Sound

    It won't be there when you view source. PHP is a server-side language. The code remains on the server. For it to work, you need to use a PHP page. Change the filename extension from .html to .php.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points