Loading scripts after page load?

后端 未结 7 1655
粉色の甜心
粉色の甜心 2020-11-27 15:16

I work with an advertising company, where we tag certain pages to track activity. A client of mine wants to fire off a javascript tag to track activity AFTER the page has fi

7条回答
  •  被撕碎了的回忆
    2020-11-27 15:28

    http://jsfiddle.net/c725wcn9/2/embedded

    You will need to inspect the DOM to check this works. Jquery is needed.

    $(document).ready(function(){
       var el = document.createElement('script');
       el.type = 'application/ld+json';
       el.text = JSON.stringify({ "@context": "http://schema.org",  "@type": "Recipe", "name": "My recipe name" });
    
       document.querySelector('head').appendChild(el);
    });
    

提交回复
热议问题