HTML and CSS Reference
In-Depth Information
The domain parameter is important because it ensures that if a different page is loaded into
the iframe, either by the user clicking a link or through some other activity, the message
won't be passed. It's possible to pass a wildcard,
'*'
, as the second parameter and avoid
all the security, but be careful because you could end up sending your user's information to
a malicious website.
When a window receives a message, the aptly named
message
event is fired. As usual,
with DOM events this handler can either be attached declaratively using an
onmessage
attribute on the
body
element or with
addEventListener
:
window.addEventListener('message', receiver, false);
The
receiver
function will accept the event as a parameter. The message passed will be
in the
data
property of the event. In the next section, you'll implement
receiver
func-
tions in the context of the planner and chat apps you built in previous sections.
4.3.2. Joining the applications with cross-document messaging
At this point, you have two applications, from different servers, coexisting in the same web
page. In this section, you'll use the cross-domain messaging API to allow the data in the
planner object to be used to feed an auto-complete feature in the chat window. This will
offer user names and task titles in a drop-down list to speed up typing while retaining ac-
curacy, as shown in
figure 4.11
.