1

In the example below, the loaded script will appear in the 'head' with a plain 'script' tag but how do I add an id into the declaration so the result is something like 'script id="my-script"'

$document->addScriptDeclaration('
    window.event("domready", function() {
        alert("An inline JavaScript Declaration");
    });
');
3

JDocument has a method for inserting arbitrary characters into the head tag. People usually use it for meta tags etc. It's down the bottom of this page:

https://docs.joomla.org/J3.x:Adding_JavaScript_and_CSS_to_the_page

$document = JFactory::getDocument();
$document->addCustomTag( '<script id="my-script">window.event("domready", function() { alert("An inline JavaScript Declaration"); });</script>' );
  • Ahhh, thank you. I'll give this a try. Cheers. – user1148731 Oct 2 '17 at 7:21

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.