Tarayıcılarda (Browser) kullanılabilir yükseklik (height) ve genişlik (width) nasıl öğrenilebilir?

February 17, 2009 at 5:43 AMoozturk

Hepimiz elbette ki farklı tarayıcılar (browser) kullanıyoruz. Bu sebeple bir web sitesi hazırlarken zaten bu tarayıcılara özgü değişkenleri kullanıyoruz. Eğer kullanıcının kullandığı tarayıcısında ne kadar yere sahip olduğunuzun sizin için önemi varsa ve bu değerleri nasıl alabileceğinizi bilmiyorsanız hiç internette aramaya kalkmayın gerçekten onlarca yerde yazıyor ancak sıkılana kadar bakacağınız yerlerdeki örneklerin hepsi ya fazla eksik* ya da yanlış çalışıyor. Onlarca yere baktıktan sonra kendi kodumu kendim yazmaya karar verdim, aşağıdaki kodu IE7, IE8 Beta, FireFox 3.0.6 ve Opera 9.63'de denedim ve evet çalışıyor.

Aşağıda bulacağınız örnekte yalnızca height değerlerini verdiğim halde aynı işlemi width için de kullanabilirsiniz netice de.

   functıon GetHeight()

  {

       var winHt;

        if (navigator.appName.indexOf("Netscape") != -1)  {
            winHt = window.innerHeight;
        }
        else
        {
            winHt = document.documentElement.clientHeight;
        }
        if(!winHt)
            winHt = document.body.clientHeight;

     return winHt;

  }

 

Bu örnekte scrollbarlarında olduğu yerler dahil olarak kullanıcının tarayıcısının toolbarlar çıkarıldıktan sonra kalan kullanılabilir alanını görebilirsiniz. Buna birçok durumda ihtiyacınız olacaktır zaten.

Scrollbarları da hesaba katmak için elde ettiğiniz değerlerin ortalama olarak 16 - 20 arasında eksik almanız gerekiyor. Misal yukarıdaki örnekte 650 height değeri aldıysanız IE için 20, Firefox için 16 olan scrolbar ebadını çıkartmanız durumunda 634 - 630 değerlerini kullanabilirsiniz.

* Mutlaka benim verdiğim örnek de eksik kalacaktır ama şimdilik çalışıyor.

Posted in: Javascript | Html

Tags: , , , , , ,

Comments (12) -

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work.

Reply

I have been checking out your posts for the last couple of hours, and everything has been very informative and well written.  I just wanted to tell you that for some reason this one doesn't seem to work in Internet Explorer.  On a side note, I was wondering if you wanted to swap blogroll links?  I hope to hear from you soon!

Reply

Pretty good post. I just came across your site and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon.

Reply

I wish getting over a broken heart can be so easy as following a few steps.. but its not:

Reply

Advantageously, the article is really the best on this notable topic. I harmonise with your conclusions and will thirstily look forward to your approaching updates

Reply

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

Reply

We've been getting excited about checking this approach also. Awesome read.

Reply

Appreciate another excellent post. I get a presentation next week, and I will be on the look out for this type of information and facts.

Reply

When are you going to post again? You really entertain me!

Reply

Mate! This site is awesome. How do you  make it look like this .

Reply

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading