Home > Web Front-end > HTML Tutorial > Please teach the parent window how to control the child window_html/css_WEB-ITnose

Please teach the parent window how to control the child window_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:01:42
Original
1410 people have browsed it

I open b.html in a.html. After opening it, I want to modify some content in b. For example, there is a text box in b. I want to modify it in a. What should I do? ?
I tried this, but it didn’t work:
In a:
function openhtml(){
var childwin = window.open("b.html");

childwin. document.getElementById("textbox").value="abcde";
}

bpage


Reply to the discussion (solution)

I don’t know how to study. A hero is coming

var obj = parent.frames[" frameName"].window;
Get the object of the sub-window
obj.document.getElementById('clientID')
Get the document node of the object of the sub-window

Please try again~ ~See

cannot be implemented. You can only pass the address bar (or cookie) parameters and let the b page handle it according to the parameters.

Alternative implementation:
Method 1:
a page In the click event, write a Session (or static variable, the same thing) to the server
In page b, use a timer to regularly query the server for the Session (or static variable). If there is a change, modify the page according to the value
This method can achieve the function you mentioned, with a certain delay;

Method 2:
Similar to 1, but the value is written in the client cookie, and the b page queries the cookie regularly, and there is a certain delay. , but it would be much better if there is no communication process

This function is not recommended because you should not have such a need for web programs. For the reason, please learn more about the page process, which is the running process of web programs:
Request--Response;

cannot be implemented. You can only pass the address bar (or cookie) parameters and let the b page handle it according to the parameters.

Alternative implementation:
Method 1:
Write a Session (or static variable, the same thing) to the server in the click event of page a
Use a timer in page b to regularly query the session (or static variable) on the server and find out If there is a change, modify the page according to the value
This method can achieve the function you mentioned, with a certain delay;

Method 2:
Similar to 1, but writes the value in the client cookie , there is a certain delay in the regular cookie query on the b page, but it will be much better if there is no communication process

This function is not recommended because you should not have such a need for web programs. Please understand the page process in detail. , which is the running process of a web program:
request-response;


I had a misunderstanding before. In non-cross-domain situations, when there is a reference relationship, you can directly operate it. Your problem is execution The b page has not been loaded during the operation, so the operation is invalid and will be abnormal. Just write like this:
function openhtml(){
var childwin = window.open("b.html");

childwin.onload=function(){
childwin .document.getElementById("textbox").value="abcde";
}
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template