簡體   English   中英

如何使用危險的setinnerhtml在nextjs中添加腳本標簽?

[英]How to add a script tag in nextjs with dangerouslysetinnerhtml?

我正在嘗試將 add.roll 添加到我的 nextjs 應用程序中。 我使用了危險的setinnerhtml 的腳本標簽,但它無法驗證。 我在這里想念什么?

這是代碼

<Script`

{
adroll_adv_id = "xxxxxxxxxxxxxxxxxxxx";
    adroll_pix_id = "xxxxxxxxxxxxxxxxxxxx";
    adroll_version = "2.0";

    (function(w, d, e, o, a) {
        w.__adroll_loaded = true;
        w.adroll = w.adroll || [];
        w.adroll.f = [ 'setProperties', 'identify', 'track' ];
        var roundtripUrl = "https://s.adroll.com/j/" + adroll_adv_id
                + "/roundtrip.js";
        for (a = 0; a < w.adroll.f.length; a++) {
            w.adroll[w.adroll.f[a]] = w.adroll[w.adroll.f[a]] || (function(n) {
                return function() {
                    w.adroll.push([ n, arguments ])
                }
            })(w.adroll.f[a])
        }

        e = d.createElement('script');
        o = d.getElementsByTagName('script')[0];
        e.async = 1;
        e.src = roundtripUrl;
        o.parentNode.insertBefore(e, o);
    })(window, document);
    adroll.track("pageView");
}`

/>

試試這個代碼它對我有用

import Script from 'next/script'
function MyApp() {
  return (
    <>
      <Script dangerouslySetInnerHTML={{
        __html: `Your script`}}></script>
    </>
  );
}

export default MyApp;

你可以試試這個,它可能對你有用。

      <script
        dangerouslySetInnerHTML={{
            __html: `
                adroll_adv_id = "xxxxxxxxxxxxxxxxxxxx";
                adroll_pix_id = "xxxxxxxxxxxxxxxxxxxx";
                adroll_version = "2.0";
            
                (function(w, d, e, o, a) {
                    w.__adroll_loaded = true;
                    w.adroll = w.adroll || [];
                    w.adroll.f = [ 'setProperties', 'identify', 'track' ];
                    var roundtripUrl = "https://s.adroll.com/j/" + adroll_adv_id
                            + "/roundtrip.js";
                    for (a = 0; a < w.adroll.f.length; a++) {
                        w.adroll[w.adroll.f[a]] = w.adroll[w.adroll.f[a]] || (function(n) {
                            return function() {
                                w.adroll.push([ n, arguments ])
                            }
                        })(w.adroll.f[a])
                    }
            
                    e = d.createElement('script');
                    o = d.getElementsByTagName('script')[0];
                    e.async = 1;
                    e.src = roundtripUrl;
                    o.parentNode.insertBefore(e, o);
                })(window, document);
                adroll.track("pageView");
            `,
        }}
    ></script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM