3

http://whatsmyuseragent.com/ tells you your screen resolution, javascript enabled,user agent and local time etc?

User agent is a part of HTTP header. How do they know about other information? I installed Firefox addons "Live HTTP Header" to view this information but I was only able to see user agent.

7

Because client-side Javascript code has access to that kind of information.

If you go to http://whatsmyscreenresolution.com/ (which your link links to) and press ctrl+u to view the page's (client-side) source code, you'll see things like this:

            <div class="col-md-4 col-md-offset-2 well">
                <h3>jQuery code to get window resolution:</h3>
                <p class="codeSection">
                    ; (function () {<br />
                    &nbsp; &nbsp; &nbsp;$(window).width();<br />
                    &nbsp; &nbsp; &nbsp;$(window).height();<br />
                    })();<br />
                </p>
            </div>

If it's not obvious, the $(window).width(); and $(window).height(); are the important parts here.

Note that the "website" (i.e., the server that sent you this HTML page with bits of Javascript in it) does not have any direct access to this information. They can only get if your browser runs a piece of Javascript code that sends it back to them, which this page may or may not be doing.

The documentation for the window object lists several additional properties related to size and scroll position and other stuff that all Javascript code has access to.


Since you also mentioned local time, here's the documentation for the Date object. The key bit is that new Date() will create a Date object set to the current date and time in the user's local timezone.

On the website you linked, this is done (and then redone every 10 seconds) in:

    function UpdateTime() {
        $('.local-time').text(formatAMPM(new Date()));
        setTimeout(function () { UpdateTime() }, 10000)
    };

And finally, a website can show whether or not you have Javascript enabled by displaying "No" by default:

            <td style="width: 50%;">JavaScript Enabled:</td>
            <td class="js-enabled bold">No</td>

and having a piece of Javascript code that changes the "No" to a "Yes":

        $('.js-enabled').text('Yes');

If your browser refuses to run Javascript, you see the "No". If it runs it, you see the "Yes".

  • Is there anyway I can stop/spoof this information just the way we spoof user agents? for example: my local time here is 3:00pm and I change it to 9:00pm. – Curtis Hagen Jun 7 '15 at 17:44
  • Your browser is the one executing this Javascript code, and it typically talks directly to your operating system to get much of this information. So unless your browser or your OS provides you with fine-grained spoofing options, you can't spoof individual bits of info, though you can easily stop all of it by disabling Javascript entirely. You can sorta spoof the time since most OSes let you change the system clock, but not on a per-application basis. – Ixrec Jun 7 '15 at 18:09
  • Thanks a lot for your time. I appreciate :) God bless you. – Curtis Hagen Jun 8 '15 at 5:46
  • can you answer my other question on programmers.stackexchange.com/questions/286460/… – Curtis Hagen Jun 11 '15 at 8:28
3

The site shows how it's done, actually. It has a link to http://whatsmyscreenresolution.com/ which shows two snippets down below:

JavaScript code to get screen resolution:

<script type="text/javascript">
document.write(screen.width + 'x' + screen.height);
</script>

jQuery code to get window resolution:

; (function () {
     $(window).width();
     $(window).height();
})();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.