23 Ocak 2009 Cuma

Boyutu değişen pencerenin boyutunu öğrenme(Firefox ve IE de çalışır)

,,,,,,,

İşte ie ve firefox da çalışan, pencerenin boyutunun değiştiğinden haberdar olan bir javascript örneği.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<script language="javascript" type="text/javascript">

//Browser'ın boyutu her değiştiğinde windowResized fonksiyonu çalışacak

window.onresize = windowResized;

//Do it on every window resize-
function windowResized(e){
var myWidth = 0, myHeight = 0;
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;
}
alert("Boyutlar = " + myWidth + " x " + myHeight);
}</script>

// Ayrı ayrı almaya ihtiyacınız vars aşağıdaki fonksiyonları da kullanabilirsiniz

function getWindowHeight(){
var myHeight = 0;
if( typeof( window.innerHeight ) == 'number' ) {
//Non-IE
myHeight = window.innerHeight;
} else if( document.documentElement && document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myHeight = document.documentElement.clientHeight;
} else if( document.body && document.body.clientHeight ) ) {
//IE 4 compatible
myHeight = document.body.clientHeight;
}

return myHeight;
}

function getWindowWidth(){
var myWidth = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
} else if( document.documentElement && document.documentElement.clientWidth ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
} else if( document.body && document.body.clientWidth ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
}

return myWidth;
}

</head>

<body> Yeni boyutları görmek için browser penceresinin boyutunu değiştiriniz. </body>

</html>