Reading and manipulating content methods in IFrame from the parent page _javascript tips

Source: Internet
Author: User
Basic methods of operation:
Document.frames ("frame_id"). Document.action;
Where the frame_id is the id,action of the IFRAME that the parent page needs to operate is the related operation in the IFRAME.
From this approach, you can see that document.frames ("frame_id") is used to get the ID of the IFRAME from the parent page, and the following document.action is the same as a typical script for page element operations, for example, Where the parent page references the IFRAME section as follows:
Copy Code code as follows:

<div id= "Region1" name= "Region1" >
<iframe onload= "Iframe_test ()" frameborder= "0" scrolling= "no" width= "100%" "height=" "Name=" Test_iframe "id=" Test_iframe "src="/testiframe.jsp "src=" testiframe.jsp "></iframe>

Testiframe.jsp is as follows:
Copy Code code as follows:

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" Utf-8 "%>
<table class= "data_form" align= "Center" >
<td><input name= "testname" type= "text" id= "testname" value= "TestName" ></td>
<td><input name= "decription" type= "text" id= "decription" value= "TestName"/></td>
<div >
<input name= "FS" type= "Submit" id= "FS" value= "Test" onclick= "alert (' Test ');" class= button ">

The script scripts for the actions of the IFRAME elements in the parent page are as follows:
Copy Code code as follows:

<script type= "Text/javascript" ><!--
function Iframe_test () {
if (Document.frames ("Test_iframe"). document.getElementById ("TestName"). value== "TestName")
Alert ("Test successful!");
if (Document.frames ("Test_iframe"). document.getElementById ("Decription"). value== "")
Document.frames ("Test_iframe"). document.getElementById ("Decription"). Value= "description"

This example describes the properties of reading elements in an IFRAME in the parent page and modifying the elements in the IFRAME in the parent page.

Through this example, we can see that in the parent page to access the elements of the IFRAME and the general access page elements are not fundamentally different, nothing more than the need to obtain in advance in the parent page to deal with the IFrame object, in the acquisition of the IFrame object, its operation is basically no special place.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.