function get_msg_box_top_offset() {
var window_height, scroll_top, res = 0;
if (window.parent != window) { //有父级的取父级的高度
window_height = parent.window.innerHeight;
scroll_top = parent.document.body.scrollTop;
if (scroll_top < window_height) {
res = window_height / 2;
} else {
res = scroll_top + window_height / 2 - 50;
}
} else {
window_height = window.innerHeight;
res = window_height / 2;
}
return res;
}
该函数也可以在iframe中计算出符合预期的值