Access to <body> tag in OJS 3.1.2

How do we access the site’s <body> tag to insert an onload action? We added some JS to Custom Header Plugin, but to make it work we need access to the tag.

Hi @teog,

Thanks for your question. Could you provide a bit more context as to what you’re trying to add to your journal page?

Kind Regards,
Patricia M.
Public Knowledge Project Intern

Hi @ pmangahis. thanks for your input, but the question is general so that regardless of our current needs we or anyone else may need access to the tag in the future as well.

Hi @teog,

E.g.:

<script>
window.onload = function() {
	document.getElementsByTagName("body")[0].addEventListener("click", function (event) {
		alert("Javascript event on click that is attached to the body after page loads");
	});
};
</script>

Is this what you are looking for?

Thanks @ Vitaliy, but resorting to JS for editing a tag is a bit too excessive, don’t you think?

Hmm, I’m afraid I need to know your current goal in the case if don’t want to use Javascript.
If the idea is manipulations with Smarty templates (which are then compiled to HTML), it’s better to be accomplished though creation of a child theme: PKP Theming Guide

Not sure what you mean. Do you know where the body tag is, or you don’t?!

For the default theme it’s here: https://github.com/pkp/pkp-lib/blob/master/templates/frontend/components/header.tpl#L25

But before any modifications of the OJS core front-end templates, I suggest getting familiar with the theming guide. The OJS upgrade process would be much easier if make changes through a child theme.