1

I'm currently working with google plus button. The values return by google plus is based on what is included at the meta on my head tag

And I have a list to be submitted using g+1 but it is under the tags that's why I can't update what is going to be posted on google plus

these are my codes

<meta itemprop="name" content="<?=$content?>">
<meta itemprop="description" content="<?=$description?>">
<meta itemprop="image" content="http://mysite/image.png">

below those lines are

    <div> content to submit by g+1
        <div class='g-plusone' data-size='medium' data-annotation='none'></div>
    </div>

    <div> content to submit by g+1
        <div class='g-plusone' data-size='medium' data-annotation='none'></div>
    </div>

    <div> content to submit by g+1
        <div class='g-plusone' data-size='medium' data-annotation='none'></div>
    </div>

 etc.

how can I use javascript, so whenever the mouse hover on the google plus button, I can update what is the value on my meta?

like

<div onmouseover='change_meta(x)' class='g-plusone' data-size='medium' data-annotation='none' ></div>

I already know how to pass argument on javascript functions. What I want to know is, what do I need to include inside that functions so I can update the meta values.

<script language="JavaScript">
function change_meta(x) {
   what do i need to do here?
}
</script>
Sam San
  • 6,567
  • 8
  • 33
  • 51
  • 1
    Any meta tag tag you change on your browser will not be picked up by google plus. you need to change the meta tag on the server for it to take effect – mplungjan Jan 05 '13 at 09:13
  • Possible duplicate of http://stackoverflow.com/questions/2568760/is-it-possible-to-use-javascript-to-change-the-meta-tags-of-the-page – asgoth Jan 05 '13 at 11:53

1 Answers1

2

Any meta tag tag you change on your browser will not be picked up by anyone reading the html from your server. You need to change the meta tag on the server for it to take effect unless the site in question is using a bookmarklet that actually reads the current content of the tag. The format you use seems to be a google proprietary microdata format

That said, if you need to change the tag you can do

var metas = document.getElementsByTagName("meta");

and loop through finding the tag you want:

for (var i=0; i<metas.length; i++) {  
  if (metas[i].getAttribute("itemprop") && 
      metas[i].getAttribute("itemprop")==="description") {
    metas[i].setAttribute("content","new description");
  }
}
mplungjan
  • 169,008
  • 28
  • 173
  • 236