1

I am attempting to place some JavaScript into a Perl script (extension .pl). The JavaScript is for interactive social media buttons, however they don't appear on the page. Here is the code that I placed in the Perl script:

<div class="sb-Container"></div>
<script
    src="https://code.jquery.com/jquery-3.3.1.min.js"
    integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
    crossorigin="anonymous">
</script>

<script src="..js/shareButtons.min.js"></script>

<script>
    $(function () {
        $(document).shareButtons({

            // Main Settings
            url: 'URL', // URL to share
            buttonSize: '50px', // Size of the share buttons. Min: 25px
            buttonsAlign: 'horizontal', // Buttons layout: horizontal, vertical
            spaceBetweenButtons: '3px', // Space between the buttons
            radius: '5px', // Buttons corner radius

            // Icons Settings
            iconSize: '20px', // Size of the social networks icons. Min: 15px
            iconColor: '#fff', // Color of the social networks icons
            iconColorOnHover: '#222', // Color of the social networks icons on hover

            // Facebook Button Settings
            showFacebookBtn: 'show',  // Display button: show, hide
            facebookBgr: '#4a6ea9', // Button background color
            facebookBgrOnHover: '#385a97', // Button background color on hover

            // Twitter Button Settings
            showTwitterBtn: 'show', // Display button: show, hide
            tweetMessage: 'Your message goes here', // Default tweet message (URL is added to the message automatically)
            twitterBgr: '#2aaae0', // Button background color
            twitterBgrOnHover: '#197bbd', // Button background color on hover 

            // Pinterest Button Settings
            showPinterestBtn: 'show', // Display button: show, hide
            pinterestBgr: '#e30b2c', // Button background color
            pinterestBgrOnHover: '#d3132a', // Button background color on hover

            // LinkedIn Button Settings
            showLinkedinBtn: 'show', // Display button: show, hide
            linkedinBgr: '#007bb6', // Button background color
            linkedinBgrOnHover: '#0e67b0', // Button background color on hover

            // VKontakte Button Settings
            showVkBtn: 'hide', // Display button: show, hide
            vkBgr: '#5b88bd', // Button background color
            vkBgrOnHover: '#688fb2', // Button background color on hover

            // WhatsApp Button Settings (this button works on mobile devices only)
            showWaBtn: 'show', // Display button: show, hide
            waBgr: '#37d350', // Button background color
            waBgrOnHover: '#25e47a', // Button background color on hover

            // Viber Button Settings (this button works on mobile devices only)
            showViberBtn: 'show', // Display button: show, hide
            viberBgr: '#665eaa', // Button background color
            viberBgrOnHover: '#675fa7', // Button background color on hover

            // Email Button Settings
            showEmailBtn: 'show', // Display button: show, hide
            emailBgr: '#888888', // Button background color
            emailBgrOnHover: '#7a7a7a', // Button background color on hover

            // Print Button Settings
            showPrintBtn: 'show', // Display button: show, hide
            printBgr: '#888888', // Button background color
            printBgrOnHover: '#7a7a7a', // Button background color on hover
        })
    });
</script>

The HTML shows:

1009 1009function () {
1009 1009document).shareButtons({

in place of:

$(function () {
    $(document).shareButtons({

Should I be placing anything within special characters?

Thanks for your help

1 Answer 1

3

Assuming you add your code in some "here-Doc" like

print <<EOT;
<div class="sb-Container"></div>
                            <script
                            src="https://code.jquery.com/jquery-3.3.1.min.js"
                            integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
                            crossorigin="anonymous"></script>
                        
...
EOT

you have to change the initial <<EOT; to <<'EOT'; indicating that you don't want special Elements (Variables, etc) to be escaped.

Be aware that despite that \\ and \' will be printed as \ and ', so you might have to "fix" that.

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for your response. I searched the perl document for '<<' and' EOT', but could not find anything. Would it be possible to add any code directly to the two lines in question, in order to ensure that nothing there is escaped?
Look for the first "perl" statement Before the code you added. It is difficult to guess what it is,
if e.g. there was a $html = qq( .. you cannot easily change this to the equivalent of $html = q( .., as you would have edit your code to escape the ).
The first perl statement before the added code is 'my $content = qq{', and the next line is HTML. my $content = qq{ is on one line. The very next line is <div class="row">. I did not understand your last comment.
my $content = qq{ will take all the content UPTO the closing }, if this is many lines below. The closing curly braces of your JS-code would be a syntax error.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.