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 12 of 12

Thread: Window Closing

  1. #1
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Window Closing

    hi,

    I have a window which contains some textfields and if the user does not want to fill the textfield and closes the window @ the top right and it should open another web page. Anyone know the solution for this.

    Any with sample coding, r highly appreciated.

    Thanx

    Balan

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    You can create a function to check if the fields have values and then call it with the onunload event handler.
    By the way, why would you want to do this?

  • #3
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi Brando,

    i am getting some personel information from the user, if the user does not want to give info and closes the window then another link should be opened.

    Thanx

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Why take the users ability to close the window away from them? But, this will give you a push in the right direction:
    Code:
    <script language="javascript">
    function check()
    {
    	if(document.forms[0].blah.value == "")
    		window.open('http://www.google.com','');
    
    }
    </script>
    Then call it on with the onunload event handler:
    Code:
    <body onunload="check();">

  • #5
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi,

    The problem i face is that a customer is displayed a page requesting him for his name & e-mail id. If the customer doesn't enter his personal details & closes the window by clciking on the "X" then the customer should be taken to the index page. Hope you are able to get my problem.

  • #6
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Alright, did you get my code? that should help you out, post back the code that you have if you are having troubles.

  • #7
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    we r not getting any value from the user then what is the use of this
    forms[0]

    and what is the use of - "blah"

    if i am using the code given by u and if i am closing the window, it normally closes it is not linking to another page.

    Thanx

  • #8
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    I figured that would point you in the direction you need, the value 'blah' is a text field I made up as an example:
    Code:
    <html>
    <head>
    <script language="javascript">
    function check()
    {
    	if(document.forms[0].blah.value == "")
    		window.open('http://www.google.com','');
    
    }
    </script>
    </head>
    <body onunload="check();">
    <form action="">
    <input type="text" name="blah">
    </form>
    </body>
    </html>

  • #9
    Regular Coder
    Join Date
    Sep 2004
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    why does the user have to close the window? why can't to just provide a link or button with "no thanks" on it that will link back to the home page?

    might some popup blockers stop the new window from coming up?

  • #10
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I copied and pasted ur code in a separate file and if i close the window(output) it normally closes, it is not redirecting to google.com. U 2 try it the way in which i did.

  • #11
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    What it does is, if you enter something in the text box, it will close, but if you leave the text box blank it will direct you to google.com.

  • #12
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,038
    Thanks
    0
    Thanked 250 Times in 246 Posts
    What andyede said. Just provide a "No, Thanks" link that will lead to the index page. Opening another window when you close a window is annoying to the user.

    <a href="index.htm">No, thanks.</a>


  •  

    Posting Permissions

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