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?