HTML5-Cross Document Messaging APIs

芮叶秋
2023-12-01

1.概述
HTML5 Cross Document Messaging是为了便于在不同源地址的页面间或是页面、浏览器的窗口、tab、iframe等间传递数据和信息。其核心是window.postMessage(data, origin)方法和message事件。
postMessage的第一个参数是要传递的数据,第二个参数是数据的来源(例如一个URL)。message事件处理程序通常会有一个参数e,e有data和origin两个属性。
捕获messge事件的方法如下:
window.addEventListener(“message”, messageHandler, true);

2.浏览器支持性检测
if(typeof window.postMessage == "undefined")
{
alert("postMessage not supported in this browser!");
}

3.

转载于:https://www.cnblogs.com/shn11160/archive/2012/12/21/2828217.html

 类似资料: