Magento – Change Meta tag information dynamically, with Jquery

jquerymagento-1.9metameta-tagsPHP

I want to change contents of Meta tag dynamically,

Here is the code which which will call the function "changeMetaInformation()" of javascript

<a onclick="changeMetaInformation('<?php  echo Mage::helper('core/url')->getCurrentUrl();?>', '<?php echo $_product->getName()?>')" href="javascript:void(0)" title="<?php echo $this->__('Share on Facebook') ?>"> 

Now here is my function which will change the Meta tag information

<script>
function changeMetaInformation(url,name)
{
    jQuery('meta[property="og:description"]').remove();
    jQuery('meta[property="og:url"]').remove();
    jQuery('meta[property="og:title"]').remove();

    jQuery("head").append('<meta property="og:url" content="'+url+'">');
    jQuery("head").append('<meta property="og:title" content="Supermax">');

    javascript:popWin('https://www.facebook.com/sharer/sharer.php?u='+url+'&t='+name, 'facebook', 'width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes')
}

And these are my Meta tags, the content of which I want to change dynamically.

<meta property="og:title" content="Join the best company in the world!" />
<meta property="og:url" content="http://www.sharethis.com" />
<meta property="og:image" content="http://sharethis.com/images/logo.jpg" />
<meta property="og:description" content="ShareThis is its people. It's imperative that we hire smart,innovative people who can work intelligently as we continue to disrupt the very category we created. Come join us!" />

Best Answer

you can change content with these below code

  jQuery("meta[property='og\\:url']").attr("content", url);

reference

Related Topic