postMessagePortal.html 頁面代碼
var targetOrigin = "http://22527.vhost20.boxcdn.cn";
var defaultTitle = "Portal";
var notificationTimer = null;
function messageHandler(e) {
if (e.origin == targetOrigin) {
notification(e.data);
} else {
// 忽略來自其他來源的訊息
}
}
function sendString(s) {
document.getElementById("widget").contentWindow.postMessage(s, targetOrigin);
}
函數notify(message) {
stopBlinking();
blinkTitle(message, defaultTitle);
}
function stopBlinking() {
if (notificationTimer !== null) {
clearTimeout(notificationTimer);
}
document.title = defaultTitle;
}
document.title = defaultTitle;
}
document.title = defaultTitle;
}
functionblinkTitle(m1, m2) {
document.title = m1;
notificationTimer = setTimeout(blinkTitle, 1000, m2, m1)
}
function sendStatus() {
var statusText = document.getElementById("statusText").value;
sendString(statusText);
}
function loadDemo() {
document.getElementById("sendButton").addEventListener("click", sendStatus, true);
document.getElementById("stopButton").addEventListener"clicking" , true);
sendStatus();
}
window.addEventListener("load", loadDemo, true);
window.addEventListener("message", messageHandler, true);
腳本>
}window.addEventListener("load", loadDemo, true);window.addEventListener("message", messageHandler, true);
顯示接收資訊: