#1
  1. Contributing User
    ASP Good Citizen (1000 - 1499 posts)

    Join Date
    May 2008
    Posts
    1,036
    Rep Power
    610

    Close window without alert message.


    Hi,

    I have this page with a form.
    I want to submit the form without closing the form.
    Also the page to which it submits should close automatically.

    Form page:
    Code:
    <form name="testform" method="post" action="Test_Page_Submit.asp" target="_blank">
    ...................
    <input type="submit" name="submit" value="submit" class="Buttons"/>
    Page to which it submits :
    Code:
    response.write("<script language=""Javascript"">") 
    response.write("window.close();") 
    response.write("</script>")
    Everything is working fine, except for one factor.
    The 2nd window while closing gives an mesaage box asking the user whether he wants to close the window or not.
    I donot want this feature.

    I have come across a statement saying that the alert doesnot come if it is a popup window ( Open to other methods also).
    But I am unable to try that out as I donot know how to open a popup window on form submission.

    Was also wondering if this kind of thing is possible without javascript.

    Thanks
    - My mind doesn't wander, most of the times, it leaves. - S R
    - Whether U agree or disagree, pls add to my rep, either ways I got ur brain thinking.
  2. #2
  3. No Profile Picture
    Help and be helped
    ASP Adventurer (500 - 999 posts)

    Join Date
    Feb 2004
    Location
    Australia
    Posts
    584
    Rep Power
    123
    Another way to do this will be to have a page called close.asp copy the code below and save as close.asp

    Code:
    <script language="JavaScript">
    <!--
    function tmt_winControl(id,c){ 
    	var d=eval(id)==null||eval(id+".closed");
    	if(!d){eval(id+"."+c);}
    }
    //-->
    </script>
    
    <body bgcolor="#FFFFFF"f" onLoad="window.close()">
    Then from your page form.asp just make the last statement after you have processed the form and checked for errors is just a simple
    PHP Code:
    Response.Redirect "close.asp" 
    .

    Comments on this post

    • new learner agrees : Thanks for being there.
    Life is Good
  4. #3
  5. Contributing User
    ASP Good Citizen (1000 - 1499 posts)

    Join Date
    May 2008
    Posts
    1,036
    Rep Power
    610
    Originally Posted by webb
    Another way to do this will be to have a page called close.asp copy the code below and save as close.asp

    Code:
    <script language="JavaScript">
    <!--
    function tmt_winControl(id,c){ 
    	var d=eval(id)==null||eval(id+".closed");
    	if(!d){eval(id+"."+c);}
    }
    //-->
    </script>
    
    <body bgcolor="#FFFFFF"f" onLoad="window.close()">
    Then from your page form.asp just make the last statement after you have processed the form and checked for errors is just a simple
    PHP Code:
    Response.Redirect "close.asp" 
    .
    Hi,

    Thanks for the reply.

    I have done as suggested, but it gives me the same alert message - " The web page you are viewing is trying to close the tab. Do you want to close this tab? Button( Yes ) Button( No )."

    There is one deviation that I have done from what you have suggested which is I have not used the Response.redirect as suggested by you.
    Instead I have continued to use the submit button to post the form data ( as shown in Post 1 ).

    There is an information which I have not given earlier, I donot know whether it is of any importance or not.

    The form is a continuous form in the sense it has n ( definite ) test questions each with option to be selected & each question has its own submit button.
    The answer selected is passed to the 2nd page which in turn adds to the or updates the database table

    &

    then I want it ( the 2nd page ) to close automatically without any alert to the user, which is not happening.

    Sorry if I am saying things which you must have already guessed.

    Thanks
  6. #4
  7. Contributing User
    ASP Good Citizen (1000 - 1499 posts)

    Join Date
    May 2008
    Posts
    1,036
    Rep Power
    610
    Hi,

    This appears to be working :

    Form Page :

    Code:
    <script type="text/javascript">
    function submitmyform(f) {
    f.target = 'foo';
    window.open('',f.target,'menubar=no,scrollbars=no, width=800,height=800');
    f.submit();
    return false;
    }
    </script>
    Code:
    		
    <form name="testform" method="post" action="Test_Page_Submit.asp" target="_blank" onsubmit="return submitmyform(this);">
    
    <input type="submit" value="submit" name="submit" />

    Test_Page_Submit.asp

    Code:
    <body onLoad="window.close()">
    Appears to be working, at least till now.

    Pls let me know if u feel there are some pitfalls or potholes in this.

    Thanks
  8. #5
  9. No Profile Picture
    Help and be helped
    ASP Adventurer (500 - 999 posts)

    Join Date
    Feb 2004
    Location
    Australia
    Posts
    584
    Rep Power
    123
    Where you have your response.write (all 3 of them) ....just replace it with the response.redirect and you're good to go.
  10. #6
  11. Contributing User
    ASP Good Citizen (1000 - 1499 posts)

    Join Date
    May 2008
    Posts
    1,036
    Rep Power
    610
    Hi,

    Thanks.
    Guess we must have been posting at the same time.

    I think i have the problem sorted out at least for the present.

    Originally Posted by webb
    Where you have your response.write (all 3 of them) ....just replace it with the response.redirect and you're good to go.
    Tried out the suggestion with a copy of the unchanged pages that I had;

    Just FYI,
    it gives an error
    "Page cannot be diplayed"
    &
    in the address bar of a new page that opens I get
    "http://localhost/T/R/Tests/%3Cscript%20language%3D%22Javascript%22%3E"

    To be very frank with you, my coding skills are not worth speaking about.
    It could be some silly mistake from my side.

    Once again Thanks a lot.
    Life is Good and All is well.
    Last edited by new learner; March 10th, 2010 at 04:32 AM.

Similar Threads

  1. window cannot close.
    By wackyflik in forum ASP Development
    Replies: 8
    Last Post: June 10th, 2005, 07:37 PM
  2. Opening confirm message in new window with JS
    By stecol in forum ASP Development
    Replies: 7
    Last Post: June 9th, 2005, 04:10 AM
  3. How to auto close a window?
    By mojito in forum ASP Development
    Replies: 5
    Last Post: July 23rd, 2004, 06:19 AM
  4. Security Alert Message box
    By pkgal79 in forum HTML, JavaScript And CSS Help
    Replies: 1
    Last Post: June 12th, 2003, 06:15 PM
  5. window on close event
    By Steve Schofield in forum ASP Development
    Replies: 2
    Last Post: December 14th, 2000, 04:09 PM

IMN logo majestic logo threadwatch logo seochat tools logo