Friday, November 26, 2010

Pop-ups

 function post_to_url(path, params, method) {  
      method = method || "post"; // Set method to post by default, if not specified.  
      //Here we are creating a form tag and adding attributes to it   
      var form = document.createElement("form");  
      form.setAttribute("method", method);  
      form.setAttribute("action", path);  
      form.setAttribute("target", "NameofthePopup");   
      //Creating input tag and adding attributes to it  
      for(var key in params) {  
           var hiddenField = document.createElement("input");  
           hiddenField.setAttribute("type", "hidden");  
           hiddenField.setAttribute("name", key);  
           hiddenField.setAttribute("value", params[key]);  
           //adding input tags to from tag.  
           form.appendChild(hiddenField);  
      }  
      document.body.appendChild(form);  // Not entirely sure if this is necessary  
      window.open('URL',"NameofthePopup","width=670,height=680,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no");  
      form.submit();// submitting the form  
 }  

  • In the above function we are using the Post method to send the parameters.
  • params should be in follwoing formate(inside the flower brackets):{Arg1:'Arg1Value',Arg2:'Arg2Value'} 

No comments: