IE不运行远程JS,但本地运行良好。

时间:2023-01-19 23:40:05

My page works in every browser except in IE 10. When I run this page locally in IE 10 there seems to be no problem whatsoever, only when I open the page remotely with IE 10.

除了IE 10,我的页面在每个浏览器中都能工作。当我在IE 10上运行这个页面时,似乎没有任何问题,只有当我用IE 10远程打开页面时。

The JavaScript is supposed to measure the div with main text and set the height and width of the div's that are off-screen. This is done wrong by IE 10. The width of these div's has to be set because otherwise the will not animate in properly when an item from the menu is clicked.

JavaScript应该用主文本来度量div,并设置分区的高度和宽度。这在IE 10上做错了。必须设置这些div的宽度,否则当单击菜单中的某个项时,将不会对其进行适当的动画处理。

I did a check on deprecated functions but found none. I checked the syntax and nothing wrong there. (as far as i can see) The console in IE does not report any errors.

我检查了弃用函数,但没有找到。我检查了语法,没有错。(据我所见)IE的控制台不会报告任何错误。

Anyone any idea as for why locally it works fine in every browser, but remotely the only browser that displays it faulty is IE?

任何人都知道为什么在本地的浏览器中,它的效果很好,但是远程唯一显示它有问题的浏览器是IE吗?

EDIT:

编辑:

I have removed the function brackets at init so the DOM can initiate, although this did not fix the problem.

我已经删除了init中的函数方括号,这样DOM就可以启动,尽管这并没有解决问题。

script (embedded in the head of the page):

脚本(嵌在页面头部):

<script src="scripts/jquery-1.10.1.min.js"></script>
<script>
var mainTextDiv = null;
var animate;
var acc = 0;
var currentTab = "home";
var nextTab;
var working = 0;
var bar = 600;
var divW;

function init(){


    onWC(currentTab);
    document.getElementById(currentTab).style.width = 'auto';
    divW = document.getElementById(currentTab).offsetWidth;
    document.getElementById("home").style.width = divW + "px";
    document.getElementById("profile").style.width = divW + "px";
    document.getElementById("news").style.width = divW + "px";
    document.getElementById("forums").style.width = divW + "px";
    document.getElementById("webshop").style.width = divW + "px";
    document.getElementById("status").style.width = divW + "px";

}

function onWC(tab){
    var divh = document.getElementById(tab).offsetHeight;
    document.getElementById('tabcontainer').style.height = ( divh + 50 ) + "px";
}
function moveDiv(tabName){
    if (currentTab == tabName){
        return;
    }
    if (working == 1){
        return;
    }
    working = 1;
    nextTab = tabName;
    removeDiv();
}
function removeDiv(){
    mainTextDiv = document.getElementById(currentTab);
    mainTextDiv.style.left = parseInt(mainTextDiv.style.left) + (0.5+acc) + "px";
    if (parseInt(mainTextDiv.style.left) > 2000){
        mainTextDiv.style.left = 2000 + "px";
        onWC(nextTab);
        getDiv();
        return;
    }

    acc += 0.15;

    animate = setTimeout(removeDiv,10);
}
function getDiv(){
    mainTextDiv = document.getElementById(nextTab);
    mainTextDiv.style.left = parseInt(mainTextDiv.style.left) - (0.5+acc) + "px";   
    if (parseInt(mainTextDiv.style.left) <= 0){
        mainTextDiv.style.left = 0 + "px";
        currentTab = nextTab;
        working = 0;
        return;
    }

    acc -= 0.15;

    animate = setTimeout(getDiv,15);
}
window.onload = init;
window.onresize = init;

$(function() {
    $("#menu ul li a").hover(
        function(){
            $(this).css("background-color", "#525252");
            $(this).css("color", "#FFF");
        },
        function() {
            $(this).css("background-color", "#FFF");
            $(this).css("color", "#525252");
        }
    );
});
</script>

1 个解决方案

#1


3  

Change window.onresize = init(); to window.onresize = init;

改变窗口。onresize = init();窗口。onresize =初始化;

As it stands, the init() is trying to run immediately when the JS file is loaded, which is throwing the error because the DOM hasn't loaded yet.

现在,init()正在尝试在加载JS文件时立即运行,因为DOM还没有加载,所以会抛出错误。

#1


3  

Change window.onresize = init(); to window.onresize = init;

改变窗口。onresize = init();窗口。onresize =初始化;

As it stands, the init() is trying to run immediately when the JS file is loaded, which is throwing the error because the DOM hasn't loaded yet.

现在,init()正在尝试在加载JS文件时立即运行,因为DOM还没有加载,所以会抛出错误。