How to add meta tag in javascript

前端 未结 4 680
攒了一身酷
攒了一身酷 2020-11-28 07:47

I want to add for a particular page.

But my pages are rendered inside one HTML

相关标签:
4条回答
  • 2020-11-28 08:24

    Try

    document.head.innerHTML += '<meta http-equiv="X-UA-..." content="IE=edge">'

    0 讨论(0)
  • 2020-11-28 08:32

    You can add it:

    var meta = document.createElement('meta');
    meta.httpEquiv = "X-UA-Compatible";
    meta.content = "IE=edge";
    document.getElementsByTagName('head')[0].appendChild(meta);
    

    ...but I wouldn't be surprised if by the time that ran, the browser had already made its decisions about how to render the page.

    The real answer here has to be to output the correct tag from the server in the first place. (Sadly, you can't just not have the tag if you need to support IE. :-| )

    0 讨论(0)
  • 2020-11-28 08:34

    $('head').append('<meta http-equiv="X-UA-Compatible" content="IE=Edge" /> ');

    or

    var meta = document.createElement('meta');
    meta.httpEquiv = "X-UA-Compatible";
    meta.content = "IE=edge";
    document.getElementsByTagName('head')[0].appendChild(meta);
    

    Though I'm not certain it will have an affect as it will be generated after the page is loaded

    If you want to add meta data tags for page description, use the SETTINGS of your DNN page to add Description and Keywords. Beyond that, the best way to go when modifying the HEAD is to dynamically inject your code into the HEAD via a third party module.

    Found at http://www.dotnetnuke.com/Resources/Forums/forumid/7/threadid/298385/scope/posts.aspx

    This may allow other meta tags, if you're lucky

    Additional HEAD tags can be placed into Page Settings > Advanced Settings > Page Header Tags.

    Found at http://www.dotnetnuke.com/Resources/Forums/forumid/-1/postid/223250/scope/posts.aspx

    0 讨论(0)
  • 2020-11-28 08:48

    Like this ?

    <script>
    var meta = document.createElement('meta');
    meta.setAttribute('http-equiv', 'X-UA-Compatible');
    meta.setAttribute('content', 'IE=Edge');
    document.getElementsByTagName('head')[0].appendChild(meta);
    </script>
    
    0 讨论(0)
提交回复
热议问题