Home  >  Article  >  Web Front-end  >  Javscript method to call functions in iframe frame page_javascript skills

Javscript method to call functions in iframe frame page_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:32:131338browse

The example in this article describes the method of calling functions in iframe frame pages in Javscript. This calling method is actually very simple. With this method, we can transfer or modify values ​​between iframes. The operation is very simple. . Share it with everyone for your reference. The specific implementation method is as follows:

Access functions inside iframe:

Copy code The code is as follows:
document.getElementById('commentIframe').contentWindow.hasLogined();

commentIframe is the id of iframe.
To execute in window.onload

Examples are as follows:

1.html

Copy code The code is as follows:

2.html page

Copy code The code is as follows:

Clicking the test button in 1.htm will invalidate the mybutton button in 2.htm (iframe page). It's that simple, haha. If you want to call the JS function in 2.htm, write this:

Copy code The code is as follows:
self.frames['a'].funtionname(param)

Call the JS function in 2.htm in 1.htm: iframe2.showInfo();

Example:

Suppose there are 2 pages, index.html and inner.html. There is an iframe in index.html, and the src of this iframe points to inner.html.

What we have to do now is:

1. Call a js method on inner.html in index.html
2. Call a js method on index.html in inner.html

The implementation code is as follows:

index.html:

Copy code The code is as follows:






This is index page.





inner.html:

Copy code The code is as follows:






This is inner page.




I hope this article will be helpful to everyone’s web programming based on JavaScript.

Statement:
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