简体   繁体   English

使用Java重置元标记

[英]Reset meta tags using Javascript

I'm using these two functions to set and reset meta tags after I instigate an JS application 在启动JS应用程序后,我正在使用这两个功能来设置和重置元标记

function setMeta(){
        alert("meta set");
        $('meta[name=viewport]').attr('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, user-scalable=0');
    }

function resetMeta(){
        alert("meta reset");
        $('meta[name=viewport]').attr('content', ' width=device-width, initial-scale=1.0,maximum-scale=1.6, user-scalable=yes, user-scalable=1');
}

My question: What is default value of the initial-scale propertie. 我的问题:初始规模属性的默认值是多少。 If I don't reset it it stays 1.0 as it was set. 如果我不重置它,它将保持设置为1.0。

Update question: If the page where I open my JS app is scaled.The page doesn't get set to 1.0 scale as in setMeta function when I open the dialog. 更新问题:如果打开我的JS应用程序的页面已缩放。打开对话框时,该页面未设置为setMeta函数中的1.0比例。 Where could the problem be? 问题可能在哪里? The other properties like user-scalable work fine... user-scalable的其他属性也user-scalable正常工作...

The default value is 1.0 , see this page : 默认值为1.0 ,请参见此页面

The viewport initial-scale parameter specifies the scale (zooming) of a web page the first time it is displayed. 视口初始比例参数指定第一次显示网页的比例(缩放)。 The default value of 1.0 specifies no scaling . 默认值1.0指定不缩放 Larger values up to 10 zoom in (enlarge) the page, and smaller values down to 0.1 zoom out (shrink) the page. 较大的值最大可放大(放大)页面10,较小的值最大可缩小(缩小)页面0.1。


To set it to the value it was before, just store it. 要将其设置为以前的值,只需存储它即可。

function setMeta(){
        alert("meta set");
        oldcontent=$('meta[name=viewport]').attr('content') //store the current value
        $('meta[name=viewport]').attr('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, user-scalable=0');
}

function resetMeta(){
        alert("meta reset");
        $('meta[name=viewport]').attr('content', oldcontent);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM