2

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!" />
2

you can change content with these below code

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

reference

3
  • Not working.... – Mrunmay Deswandikar Jan 5 '17 at 9:59
  • 1
    did you remove this code first from top jQuery('meta[property="og:url"]').remove(); – Fme Extensions Jan 5 '17 at 9:59
  • @MagentoDeveloper working perfectly for me on mozilla firefox. – Fme Extensions Jan 5 '17 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.