Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameter 'href' should represent a valid URL in facebook

facebook error

<li class="active">
  <a id="shareFB" href="https://www.facebook.com/sharer/sharer.php?u=URLENCODED_URL&t=TITLE"
  onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;" target="_blank" title="Share on Facebook">Facebook</a>
  <script type="text/javascript">document.getElementById("shareFB").setAttribute("href", "https://www.facebook.com/sharer/sharer.php?u=" + document.URL);</script>
</li>
like image 444
Shivam Dhagat Avatar asked May 24 '19 05:05

Shivam Dhagat


3 Answers

Are your using localHost. ? if you are using some plugins for share and you are in localHost then that's the issue. It will work fine when u deploy

like image 78
Thomas George Avatar answered Oct 23 '22 16:10

Thomas George


In your url, you have 'https://www.facebook.com/sharer/sharer.php?u=...' . You should try replacing 'u' with 'href' in this url.

like image 35
akg179 Avatar answered Oct 23 '22 17:10

akg179


Try This...

 function sethref() 
 {
  document.getElementById("shareFB").setAttribute("href","https://www.facebook.com/sharer/sharer.php?u=" + encodeURIComponent(document.URL));
 }
 
window.onload = sethref;
<!DOCTYPE html>
   <html>
     <title>Web Page Design</title>
   <body>
     <a id="shareFB">FB</a>
   </body>
</html>
like image 1
Hiren Patel Avatar answered Oct 23 '22 18:10

Hiren Patel