Home > Web Front-end > JS Tutorial > body text

A simple method for js to call the parent frame function and the pop-up window to call the parent page function

高洛峰
Release: 2016-12-08 11:59:33
Original
1771 people have browsed it

Call the aaa function in the parent

In the child page:

onclick="window.parent.frames.aaa()"
Copy after login

In the parent page:

function aaa()
{
alert(‘bbbbb');
}
Copy after login

The page in the frame frame needs to be changed to other pages under the same frame or the parent frame The page uses parent

window.opener refers to the parent page of the page opened by window.open.

window.frames object can refer to the page in the iframe or the page in the frameset.

can be like this

window.frames[0].document.getElementById(‘xx');
Copy after login

can be like this

window.frames[0].document.body.innerHTML;
 
frm = window.parent.window.frames[‘uploadFrame'];
frmDocument = frm.document;
frm.sb(3); //sb 是uploadFrame页面里的一个函数
Copy after login

For firefox

If you encounter an error :parent.document.frames has no properties

Just replace it with the following code. This code is compatible with IE and FF. frm = window.parent.window.frames['uploadFrame']; In fact, the frames collection is not hung on the document but It is hung under the window object.

Please note that there are restrictions on modifying the page in the frame, that is, it must be under the same domain, otherwise it cannot be accessed

If it is under the same domain, but the subdomain name is different, then the js and html involved Add one sentence to each document.

document.domain = xxx.com [这里填写你的域名]
 
document.getElementById(‘iframeid').contentWindow.document.getElementById(‘someelementid');
Copy after login

js pop-up page and call the parent page function

(for example: call the parent page function test2())
window.opener.test2();

The frame sub-page calls the previous page method

(For example: the frame frame of the previous page is named menuBar, and the onhook() function is called)
window.top.frames["menuBar"].onhook();

js pop-up page calls the parent page frame subpage function

(For example: pop-up page call, frame name is menuBar)
window.opener.top.frames['menuBar'].onhook();


Related labels:
js
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!