0

I was trying to share an image on social media. I found a solution here:

Default website image for social sharing

They say it works in this link but in my case when the window opens it diplays

Warning href should represent a valid URL

I used the same code. Here it is:

<li class="social__item">
<div id="mImageBox">
<button id="my_image" alt=''  src='../../admin/views/images/<?php echo $result['image']; ?>' class="social__link" onclick="fbs_click(this)"><i class="fa fa-facebook"></i></button>
</div>
<script>
function fbs_click(TheImg) {

    u=TheImg.src;

    t=TheImg.getAttribute('alt');

    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');

    return false;

   }
 </script>
 </li>

I was expecting it will open the sharing window with the image and share button but the result was "href should represent a valid URL" with okay button. How can I fix this or is there any other method of sharing an image on social media when clicking on a button?

Ritesh Khandekar
  • 3,885
  • 3
  • 15
  • 30

1 Answers1

0

Change u=TheImg.src; to u=TheImg.getAttribute('src'); Also note that to define variable as var u If you sharing your pic to FB then write full url using http://

Ritesh Khandekar
  • 3,885
  • 3
  • 15
  • 30
  • it works actually but not on localhost server :/ that means i cant use it right now untill i put my website on internet anyway thanks – Louay Gourrida Apr 19 '19 at 21:43