Window Open & Close

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gyanendar
    New Member
    • Jun 2007
    • 90

    Window Open & Close

    Hi All,
    I have to design a web page in which all file(pdf) present in particular folder is visible.Onclick ing particular Item,the file should open in new window.
    There is link on parent window which show wether the newly open window is still open or closed.
    I have implemented the first part through <a href="JavaScrip t..."..>txt</a>
    and able to view the file in new window.
    But the second part ,I am not able to implement.
    I try with this code

    [CODE=javascript]<script type ="text/javascript" language ="javascript " >
    var my_window =null;
    function ClosePopup()
    {
    if(my_window && my_window.close d)
    {
    alert('Window already closed!');----1
    }
    else if (my_window && my_window.open)
    {
    alert('Close the window!');
    }
    }

    function TestPopUp(My_Hr ef)
    {

    my_window = window.open(My_ Href, "mywindow","sta tus=1");
    }
    </script>[/CODE]
    .
    Every time 1st alert is getting executed irrespective of state of the child window.
    Please help.

    Manohar
    Last edited by gits; Jan 29 '08, 06:55 AM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    hi ...

    the following check should work for your function:

    [CODE=javascript]if (typeof my_window != 'undefined' && !my_window.clos ed) {
    alert('Close the window!');
    } else {
    alert('Window already closed!');
    }
    [/CODE]
    kind regards

    Comment

    • gyanendar
      New Member
      • Jun 2007
      • 90

      #3
      Hi ,
      by using above function always else part is geting executed.
      Regards,
      Manohar

      Originally posted by gits
      hi ...

      the following check should work for your function:

      [CODE=javascript]if (typeof my_window != 'undefined' && !my_window.clos ed) {
      alert('Close the window!');
      } else {
      alert('Window already closed!');
      }
      [/CODE]
      kind regards

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        then adapt the call too and use the onclick instead of href:

        [HTML]<a href="#" onclick="TestPo pUp('your_href' );">txt</a>[/HTML]
        kind regards

        Comment

        • gyanendar
          New Member
          • Jun 2007
          • 90

          #5
          Hi ,
          I have changed the code and added onclick ="fun(..)".
          But the problem is not solved as it every time executing the else part.

          Regards,
          Manohar


          Originally posted by gits
          then adapt the call too and use the onclick instead of href:

          [HTML]<a href="#" onclick="TestPo pUp('your_href' );">txt</a>[/HTML]
          kind regards

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5388

            #6
            my_window is a global variable in your page? it has to be one! :)

            Comment

            • gyanendar
              New Member
              • Jun 2007
              • 90

              #7
              Originally posted by gits
              my_window is a global variable in your page? it has to be one! :)
              Here is the code that I am using.:

              [CODE=javascript]<script type ="text/javascript" language ="javascript " >
              var my_window =null;
              function ClosePopup()
              {
              if(typeof my_window!='und efined' && !my_window.clos ed)
              {
              alert('Close the window!');

              }
              else
              {
              alert('Window already closed!');
              }
              }

              function TestPopUp(My_Hr ef)
              {
              my_window = window.open(My_ Href, "mywindow","sta tus=1");
              }
              </script>[/CODE]
              my_window is global variable.


              Regards,
              Manohar
              Last edited by gits; Jan 29 '08, 11:01 AM. Reason: added code tags

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5388

                #8
                when i simply test that code in FF it works without problems ... please post the page where you call that code ... is something reloaded elsewhere during the operation?

                kind regards

                ps: sorry i missed that you posted your code and the var declaration already in the original post so that i should have seen that your var is global :)

                Comment

                • gyanendar
                  New Member
                  • Jun 2007
                  • 90

                  #9
                  Originally posted by gits
                  when i simply test that code in FF it works without problems ... please post the page where you call that code ... is something reloaded elsewhere during the operation?

                  kind regards

                  ps: sorry i missed that you posted your code and the var declaration already in the original post so that i should have seen that your var is global :)
                  Here is the page..code

                  [CODE=asp]<%@ Page Language="VB" AutoEventWireup ="false" CodeFile="Uploa dPdf.aspx.vb" Inherits="Uploa dPdf" %>

                  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

                  <html xmlns="http://www.w3.org/1999/xhtml" >
                  <head runat="server">
                  <title>Upload PDF</title>

                  </head>
                  <script type ="text/javascript" language ="javascript " >
                  var my_window =null;
                  function ClosePopup()
                  {
                  if(typeof my_window!='und efined' && !my_window.clos ed)
                  {
                  alert('Close the window!');

                  }
                  else
                  {
                  alert('Window already closed!');
                  }
                  }

                  function TestPopUp(My_Hr ef)
                  {
                  my_window = window.open(My_ Href, "mywindow","sta tus=1");
                  }
                  </script>
                  <body >
                  <form id="form1" runat="server">
                  <div>
                  <asp:Panel ID="pnlUpload" runat ="server" GroupingText ="Upload Pdf" Width ="80%" >
                  <br />
                  <br />
                  <div style ="text-align :center ">
                  Upload File :<asp:FileUploa d ID="fuPDF" runat ="server" /> &nbsp:&nbsp;&nb sp;&nbsp;
                  <asp:Button ID="btnUpload" runat ="server" Text ="Upload" />
                  </div>
                  <br />
                  <asp:Label ID="lblStatusfu " runat ="server" ></asp:Label>
                  <br />
                  </asp:Panel>
                  <br />
                  <asp:Panel ID="pnlView" runat ="server" GroupingText ="View Uploaded File" Width ="80%">
                  <br />
                  <%--<a href="Javascrip t:TestPopUp('Pd f/abc.pdf')">Actu al Test</a>
                  <a href="Javascrip t:OpenPopup()" >Click Here</a>--%>
                  <a href ="Javascript:Cl osePopup()">Vie w Status</a>
                  <br />
                  <div id ="divFileLis t" runat ="server" ></div>
                  <br />
                  <asp:Label ID="lblFileStat us" runat ="server" ></asp:Label>
                  <br />
                  </asp:Panel>
                  </div>

                  </form>
                  </body>
                  </html>
                  Imports System.IO
                  Partial Class UploadPdf
                  Inherits System.Web.UI.P age

                  Protected Sub btnUpload_Click (ByVal sender As Object, ByVal e As System.EventArg s) Handles btnUpload.Click
                  If fuPDF.HasFile Then

                  End If
                  End Sub

                  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load
                  Dim fName As String = ""
                  Dim dirInfo As DirectoryInfo = New DirectoryInfo(" C:\Gyanendar\We bSites\TestWeb\ Pdf")
                  Dim file As FileInfo
                  For Each file In dirInfo.GetFile s()
                  fName += "<a href=""#"" onclick=""TestP opUp('Pdf/" + File.Name + "');"">" + File.Name + "</a>" + "</br>"
                  Next
                  divFileList.Inn erHtml = fName
                  End Sub
                  End Class[/CODE]
                  .

                  With simple HTML page it may work.I need it for pdf for which it is not working.

                  Regards,
                  Gyanendar
                  Last edited by gits; Jan 29 '08, 12:26 PM. Reason: added code tags

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5388

                    #10
                    hi ...

                    i'm not very familiar with asp ... but it should work with any window that you open by a javascript window.open() ... could you please send the source view as it turns out in the browser, i mean the rendered page? ... so i could test it here locally?

                    kind regards

                    Comment

                    • gyanendar
                      New Member
                      • Jun 2007
                      • 90

                      #11
                      Hi,
                      Here is the source View Code:

                      [HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

                      <html xmlns="http://www.w3.org/1999/xhtml" >
                      <head><title>
                      Upload PDF
                      </title></head>
                      <script type ="text/javascript" language ="javascript " >
                      var my_window =null;
                      function ClosePopup()
                      {
                      if(typeof my_window!='und efined' && !my_window.clos ed)
                      {
                      alert('Close the window!');
                      }
                      else
                      {
                      alert('Window already closed!');
                      }
                      }

                      function TestPopUp(My_Hr ef)
                      {
                      my_window = window.open(My_ Href, "mywindow","sta tus=1");

                      }
                      </script>
                      <body >
                      <form name="form1" method="post" action="UploadP df.aspx" id="form1" enctype="multip art/form-data">
                      <div>
                      <input type="hidden" name="__VIEWSTA TE" id="__VIEWSTATE " value="/wEPDwULLTIxMTgy NzkwNDMPZBYCAgM PFgIeB2VuY3R5cG UFE211bHRpcGFyd C9mb3JtLWRhdGEW AgIDD2QWAgIBDxY CHglpbm5lcmh0bW wFvAg8YSBocmVmP SIjIiBvbmNsaWNr PSJUZXN0UG9wVXA oJ1BkZi81NV9MX1 AgQWRkcmVzcyBJb mNvcnJlY3QoUmV0 dXJuVG9JbnN1cmV kXzA5XzIzKS5wZG YnKTsiPjU1X0xfU CBBZGRyZXNzIElu Y29ycmVjdChSZXR 1cm5Ub0luc3VyZW RfMDlfMjMpLnBkZ jwvYT48L2JyPjxh I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bGljaz0iVGVzdF BvcFVwKCdQZGYvO DNfQ0xVRSBTdXJj aGFyZ2UoOF85Myk ucGRmJyk7Ij44M1 9DTFVFIFN1cmNoY XJnZSg4XzkzKS5w ZGY8L2E+PC9icj4 8YSBocmVmPSIjIi BvbmNsaWNrPSJUZ XN0UG9wVXAoJ1Bk Zi9hYmMucGRmJyk 7Ij5hYmMucGRmPC 9hPjwvYnI+ZGSqN 0yzTDwMxBKf1w+F gqEHYcTeWw==" />
                      </div>

                      <div>
                      <div id="pnlUpload" style="width:80 %;">
                      <fieldset>
                      <legend>
                      Upload Pdf
                      </legend>
                      <br />
                      <br />
                      <div style ="text-align :center ">
                      Upload File :<input type="file" name="fuPDF" id="fuPDF" /> &nbsp:&nbsp;&nb sp;&nbsp;
                      <input type="submit" name="btnUpload " value="Upload" id="btnUpload" />
                      </div>
                      <br />
                      <span id="lblStatusfu "></span>
                      <br />

                      </fieldset>
                      </div>
                      <br />
                      <div id="pnlView" style="width:80 %;">
                      <fieldset>
                      <legend>
                      View Uploaded File
                      </legend>
                      <br />

                      <a href ="Javascript:Cl osePopup()">Vie w Status</a>
                      <br />
                      <a href ="Javascript:my _window.close() ;">Close it</a>
                      <br />
                      <div id="divFileList "><a href="#" onclick="TestPo pUp('Pdf/55_L_P Address Incorrect(Retur nToInsured_09_2 3).pdf');">55_L _P Address Incorrect(Retur nToInsured_09_2 3).pdf</a></br><a href="#" onclick="TestPo pUp('Pdf/69_Surcharge minor to major accident.pdf'); ">69_Surcha rge minor to major accident.pdf</a></br><a href="#" onclick="TestPo pUp('Pdf/71A_Reissue Letter (Late Payment) (5_98).pdf');"> 71A_Reissue Letter (Late Payment) (5_98).pdf</a></br><a href="#" onclick="TestPo pUp('Pdf/71B_2nd reissue letter.pdf');"> 71B_2nd reissue letter.pdf</a></br><a href="#" onclick="TestPo pUp('Pdf/74_ First Report Surcharge (10_91).pdf');" >74_ First Report Surcharge (10_91).pdf</a></br><a href="#" onclick="TestPo pUp('Pdf/79_Policy Cancelled Then Reissued As Non-Standard Auto (4_97).pdf');"> 79_Policy Cancelled Then Reissued As Non-Standard Auto (4_97).pdf</a></br><a href="#" onclick="TestPo pUp('Pdf/82_4-Pay to EFT.pdf');">82_ 4-Pay to EFT.pdf</a></br><a href="#" onclick="TestPo pUp('Pdf/83_CLUE Surcharge(8_93) .pdf');">83_CLU E Surcharge(8_93) .pdf</a></br><a href="#" onclick="TestPo pUp('Pdf/abc.pdf');">abc .pdf</a></br></div>
                      <br />
                      <span id="lblFileStat us"></span>
                      <br />

                      </fieldset>
                      </div>
                      </div>


                      <div>

                      <input type="hidden" name="__EVENTVA LIDATION" id="__EVENTVALI DATION" value="/wEWAgK6h7viDwLt 3oXMA8PGTWm3AzM 8jwPkHWured8yOq 9P" />
                      </div></form>
                      </body>
                      </html>
                      [/HTML]

                      Originally posted by gits
                      hi ...

                      i'm not very familiar with asp ... but it should work with any window that you open by a javascript window.open() ... could you please send the source view as it turns out in the browser, i mean the rendered page? ... so i could test it here locally?

                      kind regards
                      Last edited by gits; Jan 30 '08, 06:50 AM. Reason: added code tags

                      Comment

                      • gits
                        Recognized Expert Moderator Expert
                        • May 2007
                        • 5388

                        #12
                        hi ...

                        thank you ... i could only discover one error, since my_window is initialized with null we have to check for that accordingly:

                        [CODE=javascript]if (my_window != null && !my_window.clos ed) {
                        // code goes here
                        }[/CODE]
                        the 'View Status' action works as intended i think ... and gives the correct message with your posted code ... i opened one window and i closed it ... both times it worked correct ... could you tell with which test the error occurs?

                        kind regards

                        Comment

                        • gyanendar
                          New Member
                          • Jun 2007
                          • 90

                          #13
                          Hi,
                          Here my requirement is that , I have to get the status of opened window at any point of time(i.e. I have to get the wether the window is open or close.)
                          With this code I am able to open file in new window.But at any point of time I am not able to find the status of newly opned window(wether it is still open or closed).
                          The code segement
                          [CODE=javascript]function ClosePopup()
                          {
                          if(my_window!=n ull && !my_window.clos ed)
                          {
                          alert('Close the window!');
                          }
                          else
                          {
                          alert('Window already closed!');
                          }
                          }[/CODE]
                          always executing else part.
                          It means !my_window.clos ed part always returning true irrespective of state of the newly opened window.
                          This is the main problem I am facing.

                          Other problem is
                          I have added one link to close the opend window from parant window
                          [HTML] <a href ="Javascript:my _window.close() ;">Close it</a>[/HTML]
                          But whenever I am clicking this link it showing Javascript error (Permission denied)when child window is open.
                          If I close the child window than it not showing anything(no error).


                          Regards,
                          Manohar


                          Originally posted by gits
                          hi ...

                          thank you ... i could only discover one error, since my_window is initialized with null we have to check for that accordingly:

                          [CODE=javascript]if (my_window != null && !my_window.clos ed) {
                          // code goes here
                          }[/CODE]
                          the 'View Status' action works as intended i think ... and gives the correct message with your posted code ... i opened one window and i closed it ... both times it worked correct ... could you tell with which test the error occurs?

                          kind regards
                          Last edited by gits; Jan 30 '08, 08:43 AM. Reason: added code tags

                          Comment

                          • gits
                            Recognized Expert Moderator Expert
                            • May 2007
                            • 5388

                            #14
                            as i said ... the page works locally without problems ... is there a postback or something like that when you click the links? i could not reproduce the error ...

                            1. i open a new window
                            2. view state alerts -> close this window
                            3. close the window
                            4. view state alerts -> window is closed aready

                            -> so it works ... now when there is a 'silent' pagereload the my_window-variable will be set to null again ... and we loose the reference to the opened window. could this be the case? put an:

                            [CODE=javascript]alert(my_window ); [/CODE]
                            at top of the ClosePopup() function. what does it alert?

                            kind regards

                            Comment

                            Working...