Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Friday, September 18, 2009

Passing information between parent and child window.

Had a problem in fixing a javascript scenario of passing information between parent and child window.

If you are going to assign a parent windows variable from child window, that variable has the assigned value , even if the child window is closed.

But if you try to assign an object like array or something in the child window, the assigned variable or object exists in the parent window only if the child window is still open. If the child window is closed , the variable becomes null.

It seems, in this case the parent variable just has the reference to the variable in the child window and not the exact values.

In my case , i want to pass array from child to parent window and i did in the following way.


function settingParentWindowVariable(obj)
{ if(obj.length>0)
{
for(var i=0;i
parentvariable[i] = obj[i];
}
}
}

I am not sure, whether it is the correct way of doing it.But it works in this case.

PS: There exists Tech post. Atleast to serve my bad memory.

Friday, July 31, 2009

Window parent handler!!!

If there is a need to perform any operation in a parent window w.r.t the actions or events performed in the child window , but without refreshing the parent window , javascript comes in handy with its window.opener functionality.You can set/alter the values of the javascript variables in the parent window from the child window.You can also excecute the javascript functions of the parent window from the child window.Using this you can play with the entire DOM elements of the parent window.

For example,

window.opener.parent_variable1='XXX';
window.opener.parent_variable2=false;
window.opener.parent_function1();

PS :
Why did i write this?
Bcoz i will forget it in another 2 days.
And why did i write this (negligible)technical post?
Need to find the answer....
Will it be a start to write technical posts?
Should wait and see....

Wednesday, June 27, 2007

Javascript in Address bar

Recently i was asked to design a system which performs some operation.The technology used was jsp.The operation is , i have two jsp pages , first.jsp and second.jsp. 'first.jsp' has a form that takes input from the user.On submitting the form , it goes to 'second.jsp' where some database operation is carried on based on certain conditions.For example, partA of the database operation is carried on if the condition succeeds and partB is carried on if the condition fails.But the condition parameter is neither hardcoded nor supplied by the user through the GUI. The user need to add the condition parameter to the url in the address bar.

for example like ,

"http://www.mydomain.com/second.jsp?conditionparameter=parametervalue"

Since the url ("http://www.mydomain.com/second.jsp") has been already specified in the forms action attribute of the 'first.jsp',as well as the option of getting the condition parameter from the user through popup or alert or anykind of GUI is restricted , and passing the conditionparameter as the query string is the only way allowed i tried fetching the URL from the address bar through some javascript and jsp methods.

In the case of javascript , i tried using document.location and windows.location.href, windows.location.search etc. In the case of jsp , i tried httpservletrequest , response objects methods.But in both cases , i could not get the condition parameter that i specify in the address bar.

After a long head ache, i found the strength of java script. yes , i just typed the javascript in the address bar while being in the 'first.jsp' page.

This is the following code , i just typed in the address bar after cleaning the url already present there.

javascript:document.formname.action="http://www.mydomain.com/second.jsp?conditionparameter=parametervalue"
Thats it. Finally the form details along with the condition parameter has been caught in the 'second.jsp' and the task was completed successfully.