Skip to content

Instantly share code, notes, and snippets.

@thiagoeliasr
Last active October 8, 2022 01:24
Show Gist options
  • Save thiagoeliasr/328882806a58f600b7eb to your computer and use it in GitHub Desktop.
Save thiagoeliasr/328882806a58f600b7eb to your computer and use it in GitHub Desktop.
Display ViewPort and Screen Resolution at the top of screen. (This script was created intended to be a bookmarklet)
$(document).find('body').append('<div id="div-width-top" style="position: fixed; right: 5px; top: 5px; background: #000; color: #fff; padding: 10px; z-index: 99999; opacity: 0.7">Window Size:</div>');
$('#div-width-top').html('ViewPort: ' + window.innerWidth + 'px | Window: ' + screen.width + 'px');
$(window).resize(function() {
$('#div-width-top').html('ViewPort: ' + window.innerWidth + 'px | Window: ' + screen.width + 'px');
});
@brunomonteiro3
Copy link

To use as bookmarklet, just create a new item on your browser, and register the code as the URL:

javascript:(function()%7Bfunction%20callback()%7B(function(%24)%7Bvar%20jQuery%3D%24%3B%24(document).find('body').append('%3Cdiv%20id%3D%22div-width-top%22%20style%3D%22position%3A%20fixed%3B%20right%3A%205px%3B%20top%3A%205px%3B%20background%3A%20%23000%3B%20color%3A%20%23fff%3B%20padding%3A%2010px%3B%20z-index%3A%2099999%3B%20opacity%3A%200.7%22%3EWindow%20Size%3A%3C%2Fdiv%3E')%3B%24('%23div-width-top').html('ViewPort%3A%20'%20%2B%20window.innerWidth%20%2B%20'px%20%7C%20Window%3A%20'%20%2B%20%24(window).width()%20%2B%20'px')%3B%24(window).resize(function()%20%7B%24('%23div-width-top').html('ViewPort%3A%20'%20%2B%20window.innerWidth%20%2B%20'px%20%7C%20Window%3A%20'%20%2B%20%24(window).width()%20%2B%20'px')%3B%7D)%7D)(jQuery.noConflict(true))%7Dvar%20s%3Ddocument.createElement(%22script%22)%3Bs.src%3D%22https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fjquery%2F1.7.1%2Fjquery.min.js%22%3Bif(s.addEventListener)%7Bs.addEventListener(%22load%22%2Ccallback%2Cfalse)%7Delse%20if(s.readyState)%7Bs.onreadystatechange%3Dcallback%7Ddocument.body.appendChild(s)%3B%7D)()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment