How to add meta tag in javascript

前端 未结 4 702
攒了一身酷
攒了一身酷 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: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. :-| )

提交回复
热议问题