我正在尝试编写缩放脚本,但实际上我想将用户的所有偏好保存在内存中,我还想使用 localstorage 来保存缩放级别的参数。
这是我写的代码:
<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>
对于本地存储,以保存缩放的值,我已经这样做了
initiale=initiale + add;
localStorage['zoom'] = initiale + add;
但是当我尝试接收本地存储值时,我已经这样做了:
windowToAdjust.document.body.style.zoom = localStorage.getitem['zoom'] + '%';
但它对我说Uncaught TypeError: Cannot read property 'zoom' of undefined
我正在寻找一个问题,但我不知道如何解决它。
此致。
SP/