Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Abdullah 2 posts 72 karma points
    Jul 16, 2021 @ 17:58
    Abdullah
    0

    How to add custom JavaScript codes in my website for all pages ?

    I need to add some custom javascript codes.

    I want to add facebook page messenger chat plugin to my website in umbraco.

    Can anyone please let me know the workflow ?

    Thanks

  • Marc Goodson 1579 posts 10545 karma points MVP 6x c-trib
    Jul 25, 2021 @ 09:35
    Marc Goodson
    1

    HI Abdullah

    There are a number of options, and it depends a little on who will be adding the code, and who might need to update it in the future, and whether there are some pages you wouldn't want it on.

    To begin with though you are looking for a 'Master layout' view.

    https://our.umbraco.com/Documentation/Tutorials/Creating-Basic-Site/Creating-Master-Template-Part-1/

    If you look in the Settings section of the backoffice and click on templates - you are looking for an existing Master Layout template that all your existing templates 'probably' share.

    if you click on one of your page templates you should see Layout="nameofmasterlayouttemplate.cshtml";

    at the top to indicate where yours is...

    if you have Layout="null";

    then that means you don't have one and it's a good idea to introduce one, the above link shows an example of how to do so.

    Anything you put in your master layout template will appear on every page, so it's an ideal place to put a piece of javascript:

    <script type="text/javascript">
    //Your custom javascript here
    </script>
    

    depending on your script this might need to be in the head section, so you'd paste it just before the closing html tag eg

        <script type="text/javascript">
        //Your custom javascript here
        </script>
    </head>
    

    or the script may need to be loaded at the bottom of the body of the template to delay it's execution eg

    <script type="text/javascript">
        //Your custom javascript here
        </script>
    </body>
    

    If you want to have control over which pages the script is loaded on or not, then you could add an 'excludeFacebookScript' checkbox on your Document Types - and check this value before writing out the script, so a site editor could choose to untick or tick the box accordingly.

    regards

    Marc

  • Abdullah 2 posts 72 karma points
    Jul 26, 2021 @ 08:00
    Abdullah
    0

    Thank you Marc

Please Sign in or register to post replies

Write your reply to:

Draft