Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
// 获得窗口宽高
function getWindowWidthAndHeight() {
var width = window.innerWidth,
height = window.innerHeight;
if (width && typeof(width) == "number" &&
height && typeof(height) == "number") {
return [width, height];
}
if (document.body && document.body.offsetWidth) {
width = document.body.offsetWidth;
height = document.body.offsetHeight;
}
if (document.compatMode=='CSS1Compat' &&
document.documentElement &&
document.documentElement.offsetWidth ) {
width = document.documentElement.offsetWidth;
height = document.documentElement.offsetHeight;
}
return [width, height];
}
// 发出窗口Resize通知
function postResizeMessage(width, height) {
document.getElementById("ifrm").contentWindow
.postMessage([width,height], "http://report.stage.lanshizi.com")
}
window.onload = function () {
var wah = getWindowWidthAndHeight()
, orgWidth = wah[0]
, orgHeight = wah[1]
, timer;
postResizeMessage(wah[0], wah[1])
var bindEvent = function (event, handler) {
if (window.addEventListener) {
window.addEventListener(event, handler, false)
} else {
window.attachEvent("on" + event.toString(), handler)
}
}
bindEvent("message", function (event) {
var msg = document.createElement("p")
, text = document.createTextNode("\"" + event.data + "\" from " + event.origin)
msg.appendChild(text)
document.body.appendChild(msg)
})
bindEvent("resize", function(){
timer = setTimeout(function () {
wah = getWindowWidthAndHeight()
if (orgWidth != wah[0] || orgHeight != wah[1]) {
clearTimeout(timer)
orgWidth = wah[0]
orgHeight = wah[1]
postResizeMessage.apply(null, wah)
}
}, 101);
});
}
var bindEvent = function (event, handler) {
if (window.addEventListener) {
window.addEventListener(event, handler, false)
} else {
window.attachEvent("on" + event.toString(), handler)
}
}
bindEvent("message", function (event) {
var msg = document.createElement("p")
, text = document.createTextNode("\"" + event.data + "\" from " + event.origin)
msg.appendChild(text)
document.body.appendChild(msg)
event.source.postMessage("got it", "http://test.easyread.ly");
})
window.onload = function () {
console.log("window.top")
window.top.postMessage("ha", "http://test.easyread.ly");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.