HTML5 the same domain and cross-domain communication between windows

Source: Internet
Author: User

One, the same domain

1. If we want to manipulate the elements inside the IFRAME, first get to the window of the introduced page. Gets the window object inside the IFRAME.

var oiframe=getelementsbytagname (' iframe ') [0].contentwindow;

You can then manipulate the DOM elements inside the IFRAME.

2.window.open () method

The window.open () method returns a Window object for the page being opened.

var newwindow=window.open (' xx.html ', ' _blank ');

Manipulate the DOM elements of a child page by NewWindow.

Second, cross-domain

1.postMessage: This object can be used to send a message to another window. The Window object that accepts Windows. PostMessage ().

Likewise we get the Window object under the IFRAME var oiframe=getelementsbytagname (' iframe ') [0].contentwindow; then send the message oiframe.postmessage (' Parameter a ', ' parameter B ');

Parameter A: Indicates that the sent data parameter B indicates the domain name that accepts the parameter (to bring the Protocol)

Finally, the event is triggered when the Accept Parameters page receives the mesage information. Can write like this

Window.addeventlistener ("Message", function (EV) {

Ev.data------This is the parameter a, take this number to judge, thus to operate this savage window;

Ev.origin-----The source of the data sent;

},false)

2-Word Page Action parent page

Window---refers to the current window page The parent---refers to the window object that contains the parent page of the current page. Top-----refers to the top-level window object.

Three,

Cross-domain resolution under AJAX requests

Header (' access-control-allow-origin:http://www.a.com '); This is the code that allows access to the resource's domain setting as follows

Cross-domain implementation under IE

Under the same domain, XMLHttpRequest

Cross-domain: oxdomainrequest

Event is onload event

HTML5 the same domain and cross-domain communication between windows

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: info-contact@alibabacloud.com 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.