$(window).width()在IE9中不起作用

Sau*_*mar 3 javascript jquery cross-browser internet-explorer-9

我正在做类似的事情:

// get the screen height and width 
var maskHeight = $(document).height(); 
var maskWidth = $(window).width();

// calculate the values for center alignment
var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2);
Run Code Online (Sandbox Code Playgroud)

但看起来它在IE9中不起作用.

tsk*_*zzy 6

试试这个:

var maskWidth = window.innerWidth;
var maskHeight = window.innerHeight;
Run Code Online (Sandbox Code Playgroud)

或者在标准兼容模式的IE 6+中:

var maskWidth = document.documentElement.clientWidth;
var maskHeight = document.documentElement.clientHeight;
Run Code Online (Sandbox Code Playgroud)