Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript Confirm Message Dialog

    http://tinyurl.com/bw2y3sr
    This is my site and I want to create a Yes and No dialogue box when user closes a browser so this popup confirm dialogue should appear. Can anyone help me?

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Do a search for "lightbox script". You can then create your form containing whatever you want it to say using that script.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript Confirm Message Dialog

    I am sorry I do not want a lightbox I want a default like confirm message
    popup with yes or no buttons

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Is this what you mean?


    Code:
    <script type = "text/javascript">
    
    window.onbeforeunload = function (evt) {
    var message = 'Are you sure you want to leave this page?';
    if (typeof evt == 'undefined') {
    evt = window.event;
    }
    if (evt) {
    evt.returnValue = message;
    }
    return message;
    }
    
    </script>
    Quizmaster: In which book is Room 101 a place to be feared?
    Contestant: 101 Dalmations

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript Confirm Message Dialog

    Yes this is fine but the main issue is I just want to show this same popup on just homepage not on the other pages . Like if some one is on "About Us " page and then closes browser then this popup should not appear, it just needs to display only on homepage is it possible?

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Quote Originally Posted by suzair View Post
    Yes this is fine but the main issue is I just want to show this same popup on just homepage not on the other pages . Like if some one is on "About Us " page and then closes browser then this popup should not appear, it just needs to display only on homepage is it possible?
    Well, yes. Just include the script on the pages where you want it.

    Before you ask, it is not possible to distinguish leaving the page (perhaps for another page) and closing the browser.
    Last edited by Philip M; 01-21-2012 at 02:34 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #7
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript Confirm Message Dialog

    Thank you for your quick reply
    Regards

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    It is also not possible to distinguish reloading the current page so any page you include that on will also display if the person decides to reload the page.

    Also all the built in dialogs are intended for debugging only and have additional options in some browsers (such as being able to disable all future dialogs or disable JavaScript completely for the site).
    Last edited by felgall; 01-21-2012 at 10:51 PM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #9
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript Confirm Message Dialog

    Thank you for your quick reply


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •