Welcome to Geeklog Wednesday, September 23 2020 @ 12:09 am EDT

Geeklog Forums

Add JavaScript before the closing body tag


Status: offline

::Ben

Forum User
Full Member
Registered: 14/01/05
Posts: 1569
Location:la rochelle, France
Hello,

What is the best way for plugins to include JavaScript just before the closing </body> tag?

Thanks,

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

suprsidr

Forum User
Full Member
Registered: 29/12/04
Posts: 555
Location:Champaign, Illinois

function plugin_getheadercode_pluginName()

-s
FlashYourWeb and Your Gallery with the E2 XML Media Player for Gallery2 - http://www.flashyourweb.com
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 14/01/05
Posts: 1569
Location:la rochelle, France
Hello,

function plugin_getheadercode_pluginName() allow to include code in the header.

This function is called from COM_siteHeader and will return additional header
* information. This can be used for JavaScript functions required for the plugin
* or extra Metatags

I would like to include some code after the footer, just before
PHP Formatted Code

<script src="myscript.js" type="text/javascript"></script>
</body>


Thanks,

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

suprsidr

Forum User
Full Member
Registered: 29/12/04
Posts: 555
Location:Champaign, Illinois
Ah, sorry read your question wrong.

There is no built-in plugin function to add to the footer, but maybe you can:
  • retrieve a footer template variable
  • add to it
  • re-add it to the footer using plugin_templatesetvars_pluginName


-s
FlashYourWeb and Your Gallery with the E2 XML Media Player for Gallery2 - http://www.flashyourweb.com
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 12/01/02
Posts: 13073
Location:Stuttgart, Germany
FWIW, there's already a feature request for this. It includes some patches that I haven't tried yet ...

bye, Dirk
 Quote

Status: offline

suprsidr

Forum User
Full Member
Registered: 29/12/04
Posts: 555
Location:Champaign, Illinois
Here I hijacked the footer's execution_time:
PHP Formatted Code

function plugin_templatesetvars_pluginName($type, &$template) {
    global $LANG01, $_PAGE_TIMER;
    $exectime = $_PAGE_TIMER->stopTimer();
    $exectext = $LANG01[91] . ' ' . $exectime . ' ' . $LANG01[92].'<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>';

    if ($type == 'footer') {
        $template->set_var( 'execution_time', $exectime );
        $template->set_var( 'execution_textandtime', $exectext );
    }
}
 

Not the most beautiful solution, but it works.

-s
FlashYourWeb and Your Gallery with the E2 XML Media Player for Gallery2 - http://www.flashyourweb.com
 Quote

Status: offline

jmucchiello

Forum User
Full Member
Registered: 29/08/05
Posts: 985
If you are going to do something like that, at least do it the nice way. Just append your data to an existing value. Of course, this doesn't work if someone removes the timer display from their footer:
PHP Formatted Code

function plugin_templatesetvars_pluginName($type, $template) {
    if ($type == 'footer') {
        $incl = '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>';
        $template->set_var( 'execution_time', $incl, 1 );
        $template->set_var( 'execution_textandtime', $incl, 1 );
    }
}
 


Oh, and you really shouldn't be serving javascript from a remote URL. That's just an XSS attack waiting to happen. Or worse, a non-attack to be blocked by overzealous browser plugins like Noscript.
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 14/01/05
Posts: 1569
Location:la rochelle, France
Thanks for all these ways.

Would be great to see this feature request #906 in the next geeklog release.

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

All times are EDT. The time is now 12:09 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content