Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi, I have two pages the first name is p1 and it is :

the second page name is p2 and it is :

function n (){
//here I want to get controls of the form s from p1 and put it in a.ss
}






What I have tried:

I think I can do it by XHR but I don't know how
Posted
Updated 25-Nov-21 6:47am
Comments
Member 14611589 25-Nov-21 11:21am    
there is form in p1 it's name is s and it has text it's name ss and it's value 11
p2 has form it's name is a and it's has text it's name ss
and it has another text it's name d and in the event onkeypress I call n()
and I want to get the control ss from p1 and put it's value in ss in p2

1 solution

Interaction between pages is only allowed if one page is a child of another, in other words the second page was launched by the first.

For the parent to access a child:

    function GetFrameByLocation(locationName) {
        for (var x = 0; x < window.frames.length; x++) {
            if (window.frames[x].location.href.indexOf(locationName) > 0)
                return window.frames[x];
        }
        return null;
    }
	
	var frame = GetFrameByLocation("p2");
	frame.window.document - this is the DOM for p2.
	
for the child to access the parent:

	parent.window.document
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900