Marcin Wiazowski

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromMarcin Wiazowski
ToMe
SubjectKonqueror/Safari and getComputedStyle during page loading
Date19 June 2008 01:55
Hello.

I've noticed that getComputedStyle function in KHTML/WebKit
browsers works only when page is loaded (when onload handler
is called).

If there is a need to use getComputedStyle during page loading,
we can:

1) call alert() function and then call getComputedStyle
2) call this function and then call getComputedStyle:

    function updateCSSRulesForKHTML()
    {
        try {
            var linkList = document.getElementsByTagName('link');
            var i;

            for(i = 0; i < linkList.length; i++) {
                linkList[i].orig_disabled = linkList[i].disabled;
                linkList[i].disabled = true;
            }

            for(i = 0; i < linkList.length; i++)
                linkList[i].disabled = linkList[i].orig_disabled;
        } catch(err) {}
    }

I have downloaded KHTML sources and searched for solution to use
getComputedStyle during page loading. After finding a solution
I've created this function. You may include it in your page
if you find it useful. This function was tested with:
Safari: 3.0, 3.0.4, 3.1, 3.1.1
Konqueror: 3.5.9, 4.0.80 beta 1

Best regards! :)
Marcin Wiazowski
FromMe
ToMarcin Wiazowski
SubjectRe: Konqueror/Safari and getComputedStyle during page loading
Date21 June 2008 09:12
Marcin,

> If there is a need to use getComputedStyle during page loading,
> we can:

Thanks for the notes. The reason that computedStyle sometimes does not
work until the page has loaded is that these browsers refuse to
calculate any layout until after onload. One of the Safari authors
recommended a much more simple hack to force it to calculate layout;
check for the offsetWidth of an element that you know must exist by now:

var ignoreme = document.documentElement.offsetWidth;
var foo = getComputedStyle(bar,null);

This seems to work in all the places I have tried it. Hope this is useful.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.