gpt4 book ai didi

javascript - IE8 出现问题 - 脚本在其他浏览器上完美运行

转载 作者:行者123 更新时间:2023-12-02 19:06:41 24 4
gpt4 key购买 nike

所以我有以下脚本,基本上可以调整屏幕上元素的位置。

它在其他浏览器上完美运行,但在 IE8 上导致错误

这是导致问题的整个函数调用

function ajax_load(){
var screenwidth = window.innerWidth
var screenheight = window.innerHeight;
var current_width = 250;
var current_height = 70;
var left = (screenwidth - current_width)/2;
var bottom = (screenheight - current_height)/2;

var secondajaxloaderElement = document.getElementById('ajax_loader');
secondajaxloaderElement.style.bottom = bottom + 'px'; // Line 308 - problematic line
secondajaxloaderElement.style.left = left + 'px';
}

知道为什么这会在 IE 上失败吗?

我从开发者工具得到的错误是:无效的论点。和一个指向的行号(308)secondajaxloaderElement.style.bottom = 底部 + 'px';

最佳答案

IE8 不支持这些:

var screenwidth = window.innerWidth
var screenheight = window.innerHeight;

http://www.w3schools.com/jsref/prop_win_innerheight.asp

查看这篇文章:

window.innerHeight ie8 alternative

这应该在 IE8 中工作:

var screenwidth = document.body.clientWidth;
var screenheight = document.body.clientHeight;

或者你也可以使用 jQuery:

var screenwidth = $(window).width;
var screenheight = $(window).height;

关于javascript - IE8 出现问题 - 脚本在其他浏览器上完美运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14244897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com