You are here

Facebook share of my blogger blog shows some javascript coding

2 posts / 0 new
Last post
Ramakrishnan
Ramakrishnan's picture
Facebook share of my blogger blog shows some javascript coding

My blogger blog shows some javascript text when I am sharing it in facebook as like below..

var mydate=new Date() var year=mydate.getYear() if (year <​ 1000) year+=1900 var day=mydate.getDay() var month=mydate.getMonth() var daym=mydate.getDate() if (daym<​10) daym="0"+daym var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday") var montharray=new Arr…

What be the problem?

admin
admin's picture
Move javascript to header

Facebook sharing detects the first <p> tag in your page from the link. Then shows the text in the sharing status page.

In your case, the problem is with your template, edit your template and move the javascript block to header.

You may include it in a function and call it in body onload event. Include the below before tag:

i.e., Include the below code above the </head> tag:

  1. <script type='text/javascript'>
  2. function displayDate()
  3. {
  4. var mydate=new Date()
  5. var datestr
  6. var year=mydate.getYear()
  7. if (year < 1000)
  8. year+=1900
  9. var day=mydate.getDay()
  10. var month=mydate.getMonth()
  11. var daym=mydate.getDate()
  12. if (daym<10)
  13. daym="0"+daym
  14. var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
  15. var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
  16. document.getElementById("dispdate").innerHTML="<p>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+"</p>";
  17. }
  18. </script>

Change the <body> tag

  1. <body onload="displayDate()">

Include id 'dispdate', where you want to display date.

  1. <p id="dispdate"></p>