Click to See Complete Forum and Search --> : checking innerWidth & Height and writing html


Bungholio
05-16-2003, 01:19 PM
hi, im just trying some script to check the width of inside the browser, and then writing a status message, which will eventually be something more complex written....btu anyways, take a look, im kinda n00b, let me know if this is close....(sorry the tabbing is all shot to ****, hope its ok)

function background() {
// set vars
var myWidth = 0, myHeight = 0;

// get window size
if( typeof( window.innerWidth ) == 'number' ) {

//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;

} else {

if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {

//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;

} else {

if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;

}
}
}

// write background
if( myWidth > 800 ) {

data = "<p>greater then 800</p>";
writeData();

} else {

data = "<p>less then 800</p>";
writeData();

}

// layer is <div id="status"></div>

}
function writeData() {
if (document.layers) {
document.layers.status.document.write(data);
document.layers.status.document.close();
} else {
if (document.all) {
status.innerHTML = data;
}
}
}

Jona
05-16-2003, 01:32 PM
Are you saying that the script is not working? (No, I didn't test it.) BTW, for document.layers, use this:
if(document.layers){
document.layers.status.document.open();
document.layers.status.document.write(data);
document.layers.status.document.close();
}