selection-sharer icon indicating copy to clipboard operation
selection-sharer copied to clipboard

Workaround to get this working when placing scripts in the head of the page

Open ahoiroman opened this issue 7 years ago • 7 comments

Hello,

I am working on including your great script to an extension for a CMS.

This CMS allows me to add JS and CSS - but always to the heading of the page.

If I do $(function() {$('p').selectionSharer();}); the popover appears and lets me share via twitter and mail - but the script does not recognize the Facebook App tag.

As I can not hack the CMS, I have to find a workaround for this script.

Any help is highly appreciated.

ahoiroman avatar Jun 15 '17 06:06 ahoiroman

@SPQRInc Do you happen to have <meta property="fb:app_id" content="<your_facebook_id_here>" /> in your page?

shri3k avatar Jun 22 '17 12:06 shri3k

Yes. This is my header:

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="canonical" href="http://127.0.0.1:8080/index.php/">
    <meta property="twitter:card" content="summary_large_image">
    <meta property="fb:app_id" content="123456789">
    <meta property="og:site_name" content="Pagekit">
    <meta property="og:title" content="Home">
    <meta property="og:description" content="Globale Meta">
    <meta property="og:url" content="http://127.0.0.1:8080/index.php/"> 

ahoiroman avatar Jun 22 '17 13:06 ahoiroman

Let's try this. Let's try adding:

$(function() {
  console.log($('meta[property="fb:app_id"]').attr("content"));
  $('p').selectionSharer();
});

instead of just

$(function() {$('p').selectionSharer();});

and see if it prints 12345679 (or your facebook app_id) in the console. If it does then we'd need to further troubleshoot to see what's going on however if it does not then that would tell us that you're invoking the $('p').selectionSharer() function prior to you having <meta property="fb:app_id" content="123456789"> on your page.

If you don't mind me asking is your CMS a SPA or fully server-side rendered site?

shri3k avatar Jun 22 '17 22:06 shri3k

Hello. I have a similar situation. Сode

$(function() { console.log($('meta[property="fb:app_id"]').attr("content")); $('p').selectionSharer(); });

added, fb:app_id displayed in the console. But the selected text does not fall into facebook

12aleksandr12 avatar Nov 22 '17 19:11 12aleksandr12

@12aleksandr12 did you mean something similar to this?

shri3k avatar Nov 23 '17 02:11 shri3k

thanks, figured out.

12aleksandr12 avatar Nov 23 '17 04:11 12aleksandr12