Javascript inside LD JSON

I am wondering if javascript can be run inside ld + json script. For example, "window.location.hostname"

<script type="application/ld+json"> { "@context": "http://schema.org", "@type": "WebSite", "url": "http://" + window.location.hostname } </script> 
+5
source share
1 answer

No, scripts like "application / ld + json" will not be executed. But you can do something like this:

 <script> var el = document.createElement('script'); el.type = 'application/ld+json'; el.text = JSON.stringify({ "@context": "http://schema.org", "@type": "WebSite", "url": "http://" + window.location.hostname }); document.querySelector('body').appendChild(el); </script> 
+9
source

Source: https://habr.com/ru/post/1207800/


All Articles