Execute JavaScript within the meta tag parameter

1

Is there any way to do what I said in the title? I tried it that way but it seems to me that it does not perform the function:

<script>
function imgPrincProdu(){
    return $('.flickity-slider > img').attr('src');
}
</script>
<meta property="og:image" content="javascript:imgPrincProdu()" />
    
asked by anonymous 17.01.2018 / 12:24

1 answer

2

As I've commented, all you have to do is assign a id to your tag and use the setAttribute method to set the new value. See the example below, where I assign "new value" to the content attribute of tag :

const ogImage = document.getElementById("og-image");

ogImage.setAttribute("content", "Novo valor");
<meta id="og-image" property="og:image" content="" />

To prove that the value has changed, simply inspect the page and fetch the tag from the body of the snippet . If everything went well, you will see content="Novo valor" .

    
17.01.2018 / 12:38