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.
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.
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
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:
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
or the script may need to be loaded at the bottom of the body of the template to delay it's execution eg
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
Thank you Marc
is working on a reply...