Home  >  Q&A  >  body text

Rewritten title: Adjust browser zoom

<p>I need to create two buttons on my website that can change the browser's zoom level ( ) (-). I chose to request browser scaling rather than CSS scaling because of image size and layout issues. </p> <p>Well, is this feasible? I've heard different accounts. </p>
P粉674757114P粉674757114396 days ago470

reply all(2)I'll reply

  • P粉824889650

    P粉8248896502023-08-21 17:27:07

    May work in IE and Chrome, but not in Firefox:

    <script>
       function toggleZoomScreen() {
           document.body.style.zoom = "80%";
       } 
    </script>
    
    <img src="example.jpg" alt="example" onclick="toggleZoomScreen()">

    reply
    0
  • P粉038856725

    P粉0388567252023-08-21 13:12:46

    I would say, it's not possible in most browsers, at least without some extra plugins. And anyway, I'd try to avoid relying on browser scaling, since implementations vary (some browsers only scale fonts, others also scale images, etc.). Unless you don't care much about user experience.

    If you need more reliable scaling, then consider using JavaScript and CSS to scale the page's fonts and images, or perhaps do the scaling server-side. This solves image and layout scaling issues. Of course, this requires more work.

    reply
    0
  • Cancelreply