Is it possible to use JavaScript to change the meta-tags of the page?

后端 未结 18 1050
后悔当初
后悔当初 2020-11-22 14:14

If I put a div in the head and display:none, than use JavaScript to display it, will this work?

Edit:

I have stuff loaded in AJAX. And as my AJAX changes the

18条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 14:48

    If we don't have the meta tag at all, then we can use the following:

    var _desc = 'Out description';
    var meta = document.createElement('meta');
    meta.setAttribute('name', 'description');
    meta.setAttribute('content', _desc);
    document.getElementsByTagName('head')[0].appendChild(meta);
    

提交回复
热议问题