>  기사  >  웹 프론트엔드  >  html5 크로스 도메인 커뮤니케이션_html5 튜토리얼 기술에서 postMessage 사용 요약

html5 크로스 도메인 커뮤니케이션_html5 튜토리얼 기술에서 postMessage 사용 요약

WBOY
WBOY원래의
2016-05-16 15:48:451629검색

postMessagePortal.html 页face代码

复system代码
代码如下:


标题


<script></p> <p>var targetOrigin = "http://22527.vhost20.boxcdn.cn";</p> <p>var defaultTitle = "포털";<br>varnotificationTimer = null;</p> <p>function messageHandler(e) {<br> if (e.origin == targetOrigin) {<br> inform(e.data);<br> } else {<br> // 다른 출처의 메시지 무시<br> }<br>}</p> <p>function sendString(s) {<br> document.getElementById("widget").contentWindow.postMessage(s, targetOrigin);<br>}</p> <p><br>function inform(message) {<br> stopBlinking();<br> 깜박임(message, defaultTitle);<br>}</p> <p>function stopBlinking() {<br> if (notificationTimer !== null) {<br>clearTimeout(notificationTimer);<br> }<br> document.title = defaultTitle;<br>}</p&gt ; <p>function flickTitle(m1, m2) {<br> document.title = m1;<br>notificationTimer = setTimeout(blinkTitle, 1000, m2, m1)<br>}</p> <p>function sendStatus() {<br> var statusText = document.getElementById("statusText").value;<br> sendString(statusText);<br>}</p> <p>function loadDemo() {<br> document.getElementById("sendButton").addEventListener("click", sendStatus, true);<br> document.getElementById("stopButton").addEventListener("click", stopBlinking, true);<br> sendStatus();<br>}<br>window.addEventListener("load", loadDemo, true);<br>window.addEventListener("message", messageHandler, true);< /p> <p></script>

跨域communica


传递信息: