+ Reply to Thread
Results 1 to 8 of 8

Thread: JavaScript:Tutorial, Screen Resolution

  1. #1
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101

    JavaScript:Tutorial, Screen Resolution

    Introduction:-
    This is a simple tutorial.. It will get the screen resolution and if you modify it a little bit you can use it to define how your website will be displayed like for example having to home pages then if the screen resolution is 1024x768 it will display index1.html and if the user has 800x600 it will display index2.html.. but then thats up to you in this tutorial I will keep it the simplest possible.

    Solution:-
    This goes between <head> tags:-
    Code:
    <script language="JavaScript">
    function res() 
    {
    alert('Screen Resolution Is '+screen.width+' by '+screen.height);
    }
    </script>
    And this as the body code

    Code:
    <body onLoad='res()'
    Explanation:-
    Can it be simpler than that?

    A Preview:-
    None

    Conclusion:-
    As Always Feedback is welcome and the full source is attached!!
    Attached Files Attached Files

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    nice, i know nothing about JavaScript but i have 2 noobie questions.

    1) How would you calculate 90% of the screen width? Could you just do it like
    Code:
    alert('Screen Resolution Is '+screen.width*.9+' by '+screen.height);
    lol?

    2) Also since i guess res() returns two values would it be possable to use screen.width as like a varible? say
    Code:
    <table width='screen.width'><tr><td>blah></td></tr></table>
    again dont laugh at me, i know nothing about JS

  4. #3
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    Quote Originally Posted by Sidewinder View Post
    1) How would you calculate 90% of the screen width? Could you just do it like
    Code:
    alert('Screen Resolution Is '+screen.width*.9+' by '+screen.height);
    Yes thats it
    2) Also since i guess res() returns two values would it be possable to use screen.width as like a varible? say
    Code:
    <table width='screen.width'><tr><td>blah></td></tr></table>
    Yes you can use it as a variable for example:-
    Code:
    <body>
    <script language="JavaScript">
    window.open('about:blank','window name','width=screen.width,height=200');
    </script>
    </body>
    This will open a new window with the width of the screen resolution using screen.width directly and height of 200
    Or you can declare screen.width as a variable and then use the variable like this:-
    Code:
    <body>
    <script language="JavaScript">
    var abc=screen.width
    window.open('about:blank','window name','width=abc,height=200');
    </script>
    </body>
    its pretty the same

    again dont laugh at me, i know nothing about JS
    Well I have nothing to laugh to.. thats why I make tutorials

  5. #4
    Jordan Guest
    Nice tutorial! Thanks!

  6. #5
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    Thanks
    Sidewinder did my post help you?

  7. #6
    xtraze is offline Programming God
    Join Date
    Dec 2006
    Location
    Sri lanka
    Posts
    911
    Rep Power
    0
    Really great tutorial and I am sure I am going to use this, thank you for sharing it.

  8. #7
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    Quote Originally Posted by xtraze View Post
    Really great tutorial and I am sure I am going to use this, thank you for sharing it.
    Hope you use it Thats why I share code, because someone might need it!

  9. #8
    mkamoski is offline Newbie
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Re: JavaScript:Tutorial, Screen Resolution

    Quote Originally Posted by TcM View Post
    This is a simple tutorial.. It will get the screen resolution...
    All --

    Please help.

    This does not seem to work for me.

    1. I set my monitor to 800x600.
    2. I view in IE8 and get screen.width=800 and screen.height=600.
    3. I view in FF3.6 and get screen.width=720 and screen.height=540

    How can I fix this?

    Please advise.

    Thank you.

    -- Mark Kamoski

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Screen resolution issue and getting rid of gaps around the edges of the screen...
    By HumansAreFriendsNotFood in forum HTML Programming
    Replies: 10
    Last Post: 06-07-2010, 11:07 AM
  2. screen resolution problem
    By jwxie518 in forum HTML Programming
    Replies: 3
    Last Post: 01-06-2010, 03:59 PM
  3. Screen Resolution problems
    By fread in forum HTML Programming
    Replies: 7
    Last Post: 10-21-2009, 08:50 PM
  4. Screen Resolution problem
    By Brandon W in forum JavaScript and CSS
    Replies: 5
    Last Post: 11-25-2008, 12:48 PM
  5. Screen resolution
    By NeedHelp in forum PHP Development
    Replies: 6
    Last Post: 05-14-2007, 11:54 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts