user750487
user750487

Reputation: 1063

javascript page zoom

Hi i develop my web site and i want to make two buttons (+ and -) with functions of ctr+ and ctr- for zoom in and zoom out of whole web page in all browsers. I need javascript code for this purpose Can anybody help?

Upvotes: 6

Views: 9415

Answers (3)

Pedram Parsa
Pedram Parsa

Reputation: 1

you can use

document.body.style.zoom

also in CSS :

element{zoom:<value>;}

Upvotes: 0

Kishore Sahasranaman
Kishore Sahasranaman

Reputation: 4230

I hope this helps you ! This will zoom the entire body tag

var currentZoom = 100;
function zoom(paramvar)
{
  currentZoom += paramvar;
  document.body.style.zoom =  currentZoom + "%" 
}
<button onclick="zoom(+10);">Zoom In</button>
<button onclick="zoom(-10);">Zoom Out</button>

Upvotes: 1

Deepu S Nath
Deepu S Nath

Reputation: 1184

You have apply a logic to retain the current zoom size and increment/decrement parameter to find the required width. You can customize the following function as per your requirement.

function zoom()
{
var wdth = 1024; //Change this variable to match your configuration
document.body.style.zoom = screen.width/1024;
document.Fm.TxAre.value=1024;
alert("1024 ? : "+screen.width/1024);
}

This is just a quick solution. There are lot of better options available in the web. Just thought of sharing an easy method without using third party solution.

Upvotes: 0

Related Questions