HTML and CSS Reference
This listing shows markup of the main web form ( Iframe.aspx ) that embeds the target web form
( Target.aspx ) using an <iframe> element. Note that for the sake of testing, Iframe.aspx and Target.aspx
are created in two separate web applications. Although this won't make them cross-domain in a real sense,
they're still cross-origin because the Visual Studio development web server assigns different port number
to different web applications.
The main web form contains a text box to accept the data to be sent to the target web form. The Send
button triggers some jQuery code that actually sends the data to the target web form. The src attribute of
the <iframe> element points to http://localhost:1052/Target.aspx . The <div> element is used to output
the data returned by the target web form.
The target web form markup is simple and consists of a <div> element that outputs the data received
from the main web form. The markup of the Target.aspx is shown next:
<form id=”form1” runat=”server”>
<div>Data Received from Main Web Form :</div>
Figure 11-2 shows the main web form and the embedded target web form at runtime.
Figure 11-2. Target web form loaded in an <iframe>
Figure 11-2 shows a sample run of the main web form. The main web form sends the string data
“Hello World!” to the target web form. The target web form outputs the data and sends back a success
message. The origin of the main form as well as that of the target web form are also displayed along with
their respective data.