我有一个scorm模块,它在我的js文件的window.open中的resizable = 1的新窗口中启动:
function OpenScormModuleWindow(scormModuleId, scormModuleUrl, title, width, height)
{
_scormModuleId = scormModuleId;
InitializeUserScormModule();
scormModuleWindow = window.open(scormModuleUrl, "title", "width=" + width + ", height=" + height + ", resizable = 1");
scormModuleWindow.focus();
}
我认为我有:
var myWidth = 0, myHeight = 0;
if (typeof (window.innerWidth) == 'number')
{
myWidth = window.innerWidth;
myHeight = window.innerHeight;
}
else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
{
myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight;
}
else if (document.body && (document.body.clientWidth || document.body.clientHeight))
{
myWidth = document.body.clientWidth; myHeight = document.body.clientHeight;
}
我得到高度和宽度,但不正确
用户现在可以调整大小,当窗口尺寸正确时,如何获取高度和宽度?
我需要获取这些值,以便保存它,下次打开窗口时,它是正确的大小。
谢谢
使用一个事件侦听器,它侦听调整大小,然后可以重置值:
window.addEventListener('resize', setWindowSize);
function setWindowSize() {
if (typeof (window.innerWidth) == 'number') {
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else {
if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else {
if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
}
}
}
如果您需要跨浏览器解决方案,请使用jQuery($.on('resize', func)
)或查看JavaScript窗口调整大小事件
您需要调用匿名函数来调用setWindowSize吗?您是否可以编写“ window.addEventListener('resize',setWindowSize);” ?