How do you debug printable CSS?

前端 未结 10 2005
耶瑟儿~
耶瑟儿~ 2020-12-02 18:09

I use Firebug and IE Developer Toolbar all the time to debug tricky CSS problems. But occasionally, a tricky bug comes up that only appears when you go to print the page.

10条回答
  •  暖寄归人
    2020-12-02 18:48

    I always used web developer toolbar (as described in the other answers), but Firebug seems to miss some styles from time to time. So I added a Bookmark to my browser and added the following Javascript as URL of the bookmark. Now I can simply switch to print style by clicking the bookmark:

    javascript:(function(){var%20h,a,f;a=document.getElementsByTagName('link');for(h=0;h

    The code above finds all stylesheet links, tests if it is media=print and if so it changes it to media=all (and hides all media=screen by replacing it with media=dontshow) and reloads the stylesheets by adding a time token to the URL. The basic reload script is from someone else, I added media part. This works great for me!

    This would be the more readable version of the JavaScript URL above for explanation:

    javascript: (function() {
        var h, a, f;
        a = document.getElementsByTagName('link');
        for (h = 0; h < a.length; h++) {
            f = a[h];
            if (f.rel.toLowerCase().match(/stylesheet/) && f.href && (f.media == 'print' || f.media == 'screen')) {
                var g = f.href.replace(/(&|\?)forceReload=\d /, '');
                if (f.media.toLowerCase().match(/screen/)) f.media = "dontshow";
                if (f.media.toLowerCase().match(/print/)) f.media = "all";
                f.href = g(g.match(/\?/) ? '&' : '?')
                'forceReload=' (new Date().valueOf());
            }
        }
    })()
    

提交回复
热议问题