Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access browser's page zoom controls with javascript

I want to assign the browser's (IE/FF) page zoom controls (Menu: View/Zoom/Zoom In_Zoom Out) to two large "(+)(-)" icons on the web page so that vision impaired visitors can use these controls conveniently.

A lot of searching for a suitable script came up empty so here I am.

Any code you know that will do this simply?

All the best...

Bob

like image 582
Bob Avatar asked Apr 05 '10 12:04

Bob


3 Answers

You should be able to set the CSS3 Transform property using JavaScript to scale content. This won't be tied to the web browser zoom functionality though.

like image 145
Dean Burge Avatar answered Sep 26 '22 00:09

Dean Burge


Can't be done at all as far as I know. As has been discussed elsewhere on SO, it is possible to detect the browser's zoom level using a number of tricks. There's no way to set them from plain JavaScript.

Maybe in a Firefox extension.

Related:

  • Catch browser’s “zoom” event in JavaScript
  • Changing the browser zoom level
  • How to detect page zoom level in all modern browsers?
like image 36
Pekka Avatar answered Sep 27 '22 00:09

Pekka


This is how I do something similar in jQuery:

I made it up last night and tested on IE7, IE8, FF3.6, Safari 5, Chrome 10, and more.

I have a banner that overflows when people zoom out on some browsers. So I check the width of my .nav. If it wraps it will be shorter that its full width.

   $(function() {

        //launch doZoomCheck on load
        doZoomCheck();

        $(window).resize(function() {
            // .resize ALSO fires when people change the zoom of their browser.
            doZoomCheck();
        });

        function doZoomCheck() {
              var width = $(".nav ul").width();
              // if the width of the banner isn't near 976 is prolly overflowing
              if ( width > 976) {
                     // change to narrow font so menu doesn't wrap funny
                     $(".nav ul li a, #footer .frankmed").css("font-family", "Arial Narrow");
              }
                 // if width is back to normal change the font back
              if ( width < 976) {
                 // remove special styles when zoomed back out
             $(".nav ul li a").attr('style','');
             }
        }
  });

I'm using jQuery 1.5, prolly works back to 1.3.2 but haven't checked.

Please note: My font size is 20px already so Arial Narrow is very legible at that size. I am not stopping the user from changing the font size. I am not overriding it. I am just changing a font. Do not use this script for evil. Don't be stupid. Accessibility is important.

like image 45
Joel Crawford-Smith Avatar answered Sep 24 '22 00:09

Joel Crawford-Smith