Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8799809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:25:20+00:00 2026-06-14T00:25:20+00:00

My question What JavaScript code will tell me where the viewport of the browser

  • 0

My question

What JavaScript code will tell me where the viewport of the browser is located relative to the screen?

Context

My web application includes an applet that allows taking a snapshot via java.awt.Robot (the applet’s jar is of course signed and is privileged to perform this).

The problem is that Robot’s createScreenCapture works with rectangles relative to the entire screen, whereas I want to capture a rectangle relative to the viewport.

A browser can obviously be anywhere on the screen, but even if it is maximized (and therefore begins at the top left of the screen, i.e. {0,0}) I still don’t know how much the content is pushed down because of the window header or some toolbars.

My research so far

It seems only IE gives the viewport position through window.screenTop/Left.

Chrome supports these, but they hold the browser position.

FF doesn’t support these, instead it has screenX/Y, but like Chrome they hold the browser position.

Making sure we all use the same terminology

Screen – AKA the desktop. for example I have a WSXGA+ (1680×1050) display. I use Windows and my taskbar is always shown at the bottom so it consumes about 50 pixels vertically.

Browser – a window that may or may not have various toolbars: address and/or bookmarks bar at the top, status/add-on bars at the bottom, etc.

Viewport – where a URL is actually being rendered.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:25:21+00:00Added an answer on June 14, 2026 at 12:25 am

    Your applet knows its location via getLocationOnScreen()

    Here is a Java applet that prints the screen location of the mouse cursor while you are inside of it:

    ScreenTest.java:

    import java.awt.Point;
    import java.awt.Graphics;
    import java.applet.Applet;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.MouseEvent;
    public class ScreenTest extends Applet implements MouseMotionListener
    {
        public ScreenTest()
        {
            this.addMouseMotionListener(this);
        }
        public void mouseDragged(MouseEvent e)
        {
        }
        public void mouseMoved(MouseEvent e)
        {
            Graphics g = getGraphics();
            Point loc=getLocationOnScreen();
    
            String s=(loc.getX()+e.getX())+":"+(loc.getY()+e.getY());
            g.clearRect(0,0,1000,100);
            g.drawString(s, 10, 10);
        }
    }
    

    screentest.html:

    <html>
        <head></head>
        <body>
            <applet code="ScreenTest.class" name="screenTest" height=100 width=1000></applet>
        </body>
    </html>
    

    Here’s a simpler example called by javascript. The applet is 1px by 1px in the upper left corner of the page.

    ScreenTest2.java:

    import java.awt.Point;
    import java.applet.Applet;
    public class ScreenTest2 extends Applet
    {
        public String test(int x, int y)
        {
            Point loc=getLocationOnScreen();
            return (loc.getX()+x)+":"+(loc.getY()+y);
        }
    }
    

    screentest2.html:

    <html>
        <head></head>
        <body onclick="buttonClick(event);" style="margin:0; border:0; height:800px">
            <applet code="ScreenTest2.class" name="screenTest2" height=1 width=1></applet>
        </body>
        <script>
            function buttonClick(evt)
            {
                alert(screenTest2.test(evt.clientX,evt.clientY));
            }
        </script>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm newer in JavaScript.So maybe my question will seem naive. My JavaScript Code: <script
Question : Beginner Level Code: Pure Javascript I had created a web page in
When coding new javascript heavy websites, which order or web browser do you code
Original question: this bit of javascript code will convert centimeters to feet. But the
I recently asked a question about formatting JavaScript code in Vim. And I've also
My question is the folowing Is there a solid javascript code to detect if
I want to generate Javascript code from an existing Java project ( original question
Below is my javascript and form code where it appends a question number (qnum)
I'm looking to developing a browser extension. This extension once installed will tell the
I stumbled upon https://codereview.stackexchange.com/questions/10610/refactoring-javascript-into-pure-functions-to-make-code-more-readable-and-mainta and I don't understand the answer since the user uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.