简体   繁体   English

字体调整器Javascript在IE8和IE7中不起作用

[英]Font Resizer Javascript Not Working In IE8 and IE7

I am trying to put a font-resizer on my company' website since a lot of our customers are the elderly and they have no idea about Ctrl + "+". 我试图在我公司的网站上放置一个字体调整器,因为我们的许多客户都是老年人,他们不知道Ctrl +“ +”。

Here are the codes we have. 这是我们的代码。 The resizer works fine under FF, Chrome, and IE9. 大小调整器在FF,Chrome和IE9下可以正常工作。 But not in IE8 and IE7. 但不是在IE8和IE7中。 I omit the create cookies/read cookies parts here. 我在这里省略了创建cookie /读取cookie的部分。

function createCookie(name,value,days) {.....codes for create cookies......}

function changeFont(incfont) {
    try{
        var p = document.getElementsByClassName('resizable');
        for(n=0; n<p.length; n++) {
            if(p[n].style.fontSize) {
                var size = parseInt(p[n].style.fontSize.replace("px", ""));
            } else {
                var size = parseInt(window.getComputedStyle(p[n],null).getPropertyValue('font-size').replace("px", ""));
            }
            p[n].style.fontSize = size+ incfont + 'px';
        }

        p = document.getElementsByTagName('p');
        for(n=0; n<p.length; n++) {
            if(p[n].style.fontSize) {
                var size = parseInt(p[n].style.fontSize.replace("px", ""));
            } else {
                var size = parseInt(window.getComputedStyle(p[n],null).getPropertyValue('font-size').replace("px", ""));
            }
            p[n].style.fontSize = size+ incfont + 'px';
        }
    } catch(err) {}
}

function readCookie(name) { ....code for read cookies ....}

function increaseFontSize() {
    var inc=0;
    try {
        var x = readCookie('textsize')
        if (x && x!=0) {
            x = parseInt(x);
            inc = x;
        }
    } catch (e) {}

    if (inc<3) {
        inc++;
        changeFont(1);
        createCookie('textsize',inc,1);
    }
}

function decreaseFontSize() {
    var inc=0;
    try {
        var x = readCookie('textsize')
        if (x && x!=0) {
            x = parseInt(x);
            inc = x;
        }
    } catch (e) {}

    if (inc>0) {
        inc--;
        changeFont(-1);
        createCookie('textsize',inc,1);
    }
}

Thanks in advance! 提前致谢! YN YN

您的解决方案对我来说似乎过于复杂,我建议您使用另一种方法,为页面主体设置基本文本大小,然后为其余元素设置百分比的字体大小,以这种方式在您希望调整所有您只需要做的网站:

$("body").css("font-size", newFontSize);

getComputedStyle doesn't work for IE prior to 9. getComputedStyle不适用于9之前的IE。

See: https://developer.mozilla.org/en-US/docs/DOM/window.getComputedStyle 请参阅: https//developer.mozilla.org/en-US/docs/DOM/window.getComputedStyle

A fix might be available here : http://snipplr.com/view/13523/ I didn't test it, 这里可能提供修复程序: http : //snipplr.com/view/13523/我没有测试过,

Good luck ! 祝好运 !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM