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

js operation iframe is compatible with various mainstream browser sample codes_javascript skills

WBOY
Release: 2016-05-16 17:28:15
Original
1191 people have browsed it

While working on a project, I encountered problems related to operating iframes. The business is very simple. In fact, when operating a form inside the iframe, a function of the parent form is called. So I wrote two very simple HTML pages for testing. Using popular online methods, Google Chrome always reported errors and failed.
The code of the parent page parent.html is as follows

Copy the code The code is as follows:

< ;html xmlns="http://www.w3.org/1999/xhtml">
<br>








The code for the subpage child.html is as follows
Copy code The code is as follows:

<br>


rrr



The popular method var t=window.parent; t.ParentFunction(); on the Internet can be called in IE, but in Google Chrome it always prompts the following error,
Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
I have been searching online for a long time but I can't find the method. Some of them are very old versions. Basically It’s useless, and it’s just what everyone else says, and it’s basically untested. So I explored it myself, and later I discovered that the method on Google Chrome is actually also possible, but it's strange that it must be released before it can be used. When called in the file system, the above error will occur.
In fact, there is another HTML5 method postMessage, so I rewrote it accordingly. The final code is as follows:
The code of the parent page parent.html is as follows
Copy the code The code is as follows:


< head> <br>








Sub-page child.html The code is as follows
Copy the code The code is as follows:


<br>



rrr



After rewriting, in the file system Although that error will also occur, the method that needs to be called is indeed called, the purpose is indeed achieved, and it does not affect the use.
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