Problem with window popup: open before file download

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • viki1967
    Contributor
    • Oct 2007
    • 263

    #1

    Problem with window popup: open before file download

    Hi all.

    I have this form:

    Code:
    <form method="POST" action="default.asp?ID=<%=strID%>">    
         <input type="image" src="download.gif">
    </form>
    I need before the download file open window popup with advice not to change the file name... can you help me?

    Kind regards
    viki
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You could add it onclick (of the image button) or onsubmit (form). You may want to use DHTML instead of a popup window, but if you want a window, use window.open().

    Comment

    • viki1967
      Contributor
      • Oct 2007
      • 263

      #3
      thanks acoder.... one example please ?

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        It's as simple as adding an onclick to the input image:
        Code:
        <input type="image" src="download.gif" onclick="window.open(...)">
        For more details on window.open(), see window.open() - MDC

        Comment

        • viki1967
          Contributor
          • Oct 2007
          • 263

          #5
          thanks... I modify and working... it's correct?

          Code:
          <form method="POST" action="default.asp?ID=<%=strID%>" onsubmit="return(richiama(this));">     
               <input type="image" src="download.gif"> 
          </form>
          
          <script language="javascript" type="text/javascript">
          <!--
          
          function richiama(parametro)
          {
          window.open('popup.asp?ID=<%=strID%>','', 'scrollbars=yes,width=550,height=350');
          }
          
          //-->
          </script>

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Should be. You don't need to pass 'this' to the function. If you want to keep a reference to the opened window to close it later, set it to a variable.

            Comment

            • viki1967
              Contributor
              • Oct 2007
              • 263

              #7
              OK... I modify:

              Code:
              <a href="#">
              <input type="image" src="download.gif" onclick="if(confirm('OK?')) return(richiama(this)); return false;"></a>
              
              <script language="javascript" type="text/javascript">
              <!--
              
              var popup = null;
              
              function richiama()
              {
                var w = 350;
                var h = 350;
                
                var pw = Math.floor((screen.width - w) / 2);
                var ph = Math.floor((screen.height - h) / 2);
              
                if (!popup || popup.closed) 
               popup = window.open("popup.asp", "scelte", "width=" + w + ",height=" + h + ",top=" + ph + ",left=" + pw);
               
                if (popup) popup.focus();
              }
              
              //-->
              </script>

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                OK, that's a lot of changes!

                You don't need 'this' for the richiama function, so change it to:
                Code:
                return richiama();
                What's the link doing on the first line? What happened to the form?

                Comment

                • viki1967
                  Contributor
                  • Oct 2007
                  • 263

                  #9
                  OK many thanks...
                  In this page the form was deleted because in the popup.asp I ask confirmation download.
                  The old form is now in the new page popup.asp

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    You're using an input element, so it still needs to be inside form tags.

                    If you're only going to use it for confirmation/information, use confirm/alert instead of opening a pop-up window.

                    Comment

                    • viki1967
                      Contributor
                      • Oct 2007
                      • 263

                      #11
                      OK, many thanks for your suggestion!

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        No problem. My pleasure.

                        Comment

                        Working...