0
votes

I have a Customer Info form that has anchor tag "close" that should close the current window. This customer form is being opened as pop up. The Customer form also has a search btn that when clicked it pop ups the search form that is being run by a javascript called searchOrder.js. So basically it is a pop up inside a pop up. The customer form's close btn is not working but when the reference to searchOrder.js is removed, it begins to work. Also, when the search pop up is open and I click the "close" anchor tag, it closes the search pop up but never the current window which is the customer form. Ive tried a lot of solutions already but nothing is working. I used self.close(), window.opener.close(), made it a btn instead of a link etc.,c alled a function onclick

    function closeWindow() {

        var closeRef;

 window.opener='x';                             
            closeRef =  window.open('','_parent','');
//or closeRef = window.open("",name);
            closeRef.close();

           }

heres my gsp code:

    <g:form  method="post" name="CustomerInfoForm" target="_parent" role="form">
    <div class="id="closeLink"><a href="JavaScript:window.close()">Close</a></div>
    <button id="searchOrderButton" type="button" class="button" onclick="searchOrder(document.forms[0].summaryMessage.value,'summaryMessageText','${createLink(action:'searchOrder')}','${createLinkTo(dir:'images',file:'closeButton.gif')}')" value="Search Order">Check Order</button>   
   </g:form>

How do I make the current window (customer info ) close? tnx

2
Why do you need a function for this? window.close() should do what you need.user1864610
The close() method closes only windows opened by JavaScript using the open method. If you attempt to close any other window, a confirm message is displayed, asking the user to choose whether the window is to be closed or not.Danish Ashfaq

2 Answers

0
votes

You should use a function like this to close your popup window :

<g:form  method="post" name="CustomerInfoForm" target="_parent" role="form">
    <div class="id="closeLink">
         <a href="JavaScript:closepopup()">Close</a>
    </div>
    <button id="searchOrderButton" type="button" class="button" onclick="searchOrder(document.forms[0].summaryMessage.value,'summaryMessageText','${createLink(action:'searchOrder')}','${createLinkTo(dir:'images',file:'closeButton.gif')}')" value="Search Order">Check Order</button>   
</g:form>

<script type="text/javascript">
   function openpopup()
   {
      my_window = window.open("","myPopup","status=1,width=100,height=100");
   }

   function closepopup()
   {
      if(false == my_window.closed)
      {
         my_window.close ();
      }
   }
</script>

EDIT : Don't forget to open your popup with the openpopup() function :

<a href="javascript: openpopup()">Open Popup Window</a>
0
votes

You can shorten window.close() to just close() and shorten window.open() to open(). Maybe you'll find what you need here, though:

http://www.w3schools.com/js/tryit.asp?filename=try_win_closed

http://www.w3schools.com/jsref/obj_window.asp