Google
 

Saturday, July 14, 2007

Posting dynamic data to a popup page

It's a common need to pass some JavaScript dynamically formatted data to a pop up page, this can be easy as you just need to append data to the URL of the pop up and open it using window.open() or simply by setting the src property of an anchor element, this is a get request.

But if the data is too big to be put in the query string (2kb+), or if you want to make it harder for the user to see and modify the passed parameters, you'll need to post this data.

this JavaScript function makes the job, I post the string ("real long data").

function PostToPopup()
{
window.open("about:blank","popup",null,null);

var hdn= document.createElement("Input");
hdn.type="hidden";
hdn.name="popupdata";

var frm= document.createElement("Form");

frm.target="popup";
frm.method="POST";
frm.action="popup.aspx";

document.body.appendChild(frm);
frm.appendChild(hdn);

hdn.value="real long data";

frm.submit();
}


You can read this value in the popup from the request..this is an ASP.NET example:
Response.Write(Request.Form["popupdata"]);

2 comments:

Wright Petter said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or learn thru Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry. JavaScript Training in Chennai

Kanye Co Jamila said...

Great Article
IEEE Final Year Projects for CSE
IEEE Project Centers in Chennai