Browser Feature Tests

by sym3tri

HTML

<html>
    <body>
        <h1>ios webkit feature detection tests</h1>
        <div id="output"></div>
    </body>
</html>

JavaScript

$(document).ready(runTests);


function runTests() {
       
    var root = document.body,
        outputNode = $('#output'),
        test  = document.createElement('div'),
        control = test.cloneNode(false),
        oldCssText = root.style.cssText,
        ret = false;       
    
    var print = function(text) {
        outputNode.html(outputNode.html() + text);
    };
    
    // normalize the document padding/margin
    root.style.cssText = 'padding:0;margin:0';
    test.style.cssText = 'position:fixed;top:0px;height:1px;width:1px;';
    root.appendChild(test);
    root.appendChild(control);

    window.scrollTo(0,1);
    ret = (test.offsetTop === 0 && control.offsetTop !== 0);
    
    var offset1 = test.offsetTop, offset2 = control.offsetTop;

    // cleanup    
    root.removeChild(test);
    root.removeChild(control);
    root.style.cssText = oldCssText;
    window.scrollTo(0,0);

    print('<br/>');
    print('test.offsetTop: ' + offset1);
    print('<br/>');
    print('control.offsetTop' + offset2);
    
    /**
    print('begin');
    print('<br/>');
    print('<br/>');
    
    print('typeof root.scrollIntoViewIfNeeded: ' + typeof root.scrollIntoViewIfNeeded);
    print('<br/>');
    
    print('fixed position supported: ' + fixedPositionSupported());
    print('<br/>');
    
    print('<br/>');
    print('<br/>');
    print('end');
    **/
}