Home

Issue: 226

Where should I put the inline script?

[issue link]

for example:

<body>
    <script>
        /* disable-eslint */
        function rem() {
            var w = Math.min(document.documentElement.getBoundingClientRect().width, 500);
            document.getElementsByTagName('html')[0].style.fontSize = w * 100 / 750 + 'px';
        }
        rem();
        window.onresize = function(){rem();};
    </script>
    <div></div>
</body>

I checked the document of vue-meta and use the code below

head: {
    title: 'starter',
    script: [
      { innerHTML: 'document.querySelector("html")' }
    ]
}

But the quotes are escaped in the browser

<script n-head="true">document.querySelector(&quot;html&quot;)</script>

I also try to put the code into the layout component, the quotes are escaped too.

Update:

I carefully checked the document of vue-meta, and solved the problem with

head: {
    title: 'starter',
    script: [
      { innerHTML: 'document.querySelector("html")' }
    ],
    __dangerouslyDisableSanitizers: ['script']
}

Thank you a lot ! I really like this project! 😍

This question is available on Nuxt.js community (#c191)