I’m trying to script a zoom but in fact I would like to save in memory all preferencies from my users, also I would like to use localstorage in order to save the parameter of their zoom level.
Here is the code I wrote:
<script language=javascript1.2 type=text/javascript><!--
var windowToAdjust = ( window.external && window.external.menuArguments ) ? window.external.menuArguments.top : window;
function focusNorm() { if( window.document.forms[0]['N'+windowToAdjust.screen.width+''] ) { window.document.forms[0]['N'+windowToAdjust.screen.width+''].focus(); } }
function setZoom(oSelect) {
if( oSelect.selectedIndex ) {
if( windowToAdjust.document.body ) {
if( windowToAdjust.document.body.style ) {
if( parseInt( oSelect.options[oSelect.selectedIndex].value ) > 100 ) {
if( !window.confirm( 'All \'drop-down\' select inputs on the page you are adjusting will no longer operate correctly. Resize anyway?' ) ) { oSelect.options[0].selected = true; return; }
}
windowToAdjust.document.body.style.zoom = oSelect.options[oSelect.selectedIndex].value + '%';
if( window.external && window.external.menuArguments ) { window.close(); }
}
}
}
}
//--></script>
<script language=javascript type=text/javascript><!--
// Par DAVID HOUSTIN www.houstin.info //
var initiale=100;
function Loupe(plusoumoins) {
var add=10;
if (plusoumoins==1) {
initiale=initiale + add;
localStorage['zoom'] = initiale + add;
}
if (plusoumoins==0) {
initiale=initiale - add;
localStorage['zoom'] = initiale + add;
}
window.setZoom;
if( windowToAdjust.document.body ) {
if( windowToAdjust.document.body.style ) {
windowToAdjust.document.body.style.zoom = localStorage.getitem['zoom'] + '%';
if( window.external && window.external.menuArguments ) { window.close(); }
}
}
}
//--></script>
for the local storage in order to save the value of the zoom i’ve done this
initiale=initiale + add;
localStorage['zoom'] = initiale + add;
But when I try to receive the local storage value I’ve done that:
windowToAdjust.document.body.style.zoom = localStorage.getitem['zoom'] + '%';
But it says to me Uncaught TypeError: Cannot read property 'zoom' of undefined
I’m looking for to find an issue, but I don’t know how to solve it.
Best regards.
SP/
getItem is a function, so you should call it like
Notice the () instead of [] and also the camelCase of getItem.