views:

36

answers:

0

i'm trying to dynamically set a metatag to the head of my document. This is a mobile device specific metatag that I need to add through code. I found this solution here:

http://stackoverflow.com/questions/2831529/having-trouble-using-jquery-to-set-meta-tag-values

but it doesnt seem to work, what am I doing wrong?

function setOrCreateMetaTag(metaName, name, value) {
    var t = 'meta['+metaName+'='+name+']';
    var mt = $(t);
    if (mt.length === 0) {
        t = '<meta '+metaName+'="'+name+'" />';
        mt = $(t).appendTo('head');
    }
    mt.attr('content', value);
}

setOrCreateMetaTag(name, viewport, 'width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0');