Jacob
Jacob

Reputation: 4031

Reset meta tags using Javascript

I'm using these two functions to set and reset meta tags after I instigate an JS application

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.

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. Where could the problem be? The other properties like user-scalable work fine...

Upvotes: 0

Views: 784

Answers (1)

Manishearth
Manishearth

Reputation: 16198

The default value is 1.0, see this page:

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. Larger values up to 10 zoom in (enlarge) the page, and smaller values down to 0.1 zoom out (shrink) the page.


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);
}

Upvotes: 1

Related Questions