postMessagePortal.html 页面代码
复制代码代码如下:
<!DOCTYPE html>
<title>标题</title>
<link rel="stylesheet" href="styles.css">
<link rel="icon" href="http://apress.com/favicon.ico">
<script></p>
<p>var targetOrigin = "http://22527.vhost20.boxcdn.cn";</p>
<p>var defaultTitle = "Portal";
var notificationTimer = null;</p>
<p>function messageHandler(e) {
if (e.origin == targetOrigin) {
notify(e.data);
} else {
// ignore messages from other origins
}
}</p>
<p>function sendString(s) {
document.getElementById("widget").contentWindow.postMessage(s, targetOrigin);
}</p>
<p>
function notify(message) {
stopBlinking();
blinkTitle(message, defaultTitle);
}</p>
<p>function stopBlinking() {
if (notificationTimer !== null) {
clearTimeout(notificationTimer);
}
document.title = defaultTitle;
}</p>
<p>function blinkTitle(m1, m2) {
document.title = m1;
notificationTimer = setTimeout(blinkTitle, 1000, m2, m1)
}</p>
<p>function sendStatus() {
var statusText = document.getElementById("statusText").value;
sendString(statusText);
}</p>
<p>function loadDemo() {
document.getElementById("sendButton").addEventListener("click", sendStatus, true);
document.getElementById("stopButton").addEventListener("click", stopBlinking, true);
sendStatus();
}
window.addEventListener("load", loadDemo, true);
window.addEventListener("message", messageHandler, true);</p>
<p></script></p>
<p><h1>跨域通讯</h1>
传递信息:<input type="text" id="statusText" value="Online">
<button id="sendButton">确定</button>
<iframe id="widget" src="/UploadFiles/2021-03-30/postMessageWidget.html"><p>
<button id="stopButton">停止标题闪烁</button>
</p>
postMessageWidget.html页面的代码
复制代码代码如下:
<!DOCTYPE html>
<title>标题</title>
<link rel="stylesheet" href="styles.css">
<script></p>
<p>var targetOrigin = "http://www.weixiu0376.cn";</p>
<p>// TODO whitelist array</p>
<p>function messageHandler(e) {
if (e.origin === "http://www.weixiu0376.cn") {
document.getElementById("status").textContent = e.data;
} else {
// ignore messages from other origins
}
}</p>
<p>function sendString(s) {
window.top.postMessage(s, targetOrigin);
}</p>
<p>function loadDemo() {
document.getElementById("actionButton").addEventListener("click",
function() {
var messageText = document.getElementById("messageText").value;
sendString(messageText);
}, true);</p>
<p>}
window.addEventListener("load", loadDemo, true);
window.addEventListener("message", messageHandler, true);</p>
<p></script>
<p>显示接收信息: <strong id="status"></strong><p>
<div>
<input type="text" id="messageText" value="填写消息内容">
<button id="actionButton">发送消息</button>
</div>
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 张小英1978-可爱的人[新加坡黑胶版][WAV+CUE]
- 张小英1978-心有千千结[新加坡黑胶版][WAV+CUE]
- 谭晶《祖国万岁·作品全集》(8CD)[WAV+CUE]
- 群星.2010-《第13届汕头音响展纪念CD》非卖品[FLAC+CUE]
- 群星.2010-《第13届汕头音响展纪念CD》非卖品[FLAC+CUE]
- 吉尔·沙汉姆-《梁祝柴科夫斯基小提琴协奏曲(GilShaham)》[WAV分轨]
- 《101系列:香港影視傳奇6CD 101首家喻户晓的影视金曲》[WAV+CUE][2.9GB]
- 蔡依林《蔡依林歌曲合集》[320k/MP3][431.6MB]
- 陈宁《破晓 HQⅡ》2024头版限量编号 [WAV+CUE][500MB]
- 瑞鸣音乐《中国音乐地图之听见河南豫剧经典唱段》2020[WAV分轨]
- 【伊比萨沙发】VA-2024-IbizaSpring2024(LoungeCocktailsfromtheHeart)[FLAC]
- 群星《世界顶级汽车音响试音王》4K金碟16CD[WAV+CUE]
- 群星-音效环绕天碟《极致环绕人声天碟天品》7CD[WAV]
- 泰拉克SACD古典试音碟7SACD-ISO
- 群星《红歌宝典》20CD[WAV/分轨]