Topics

User Functions

Events

There are no upcoming events

What's New

Stories

No new stories

Comments last 2 weeks

No new comments

Trackbacks last 2 weeks

No new trackback comments

Links last 2 weeks

No recent new links

NEW FILES last 14 days

No new files

Welcome to Geeklog Thursday, May 23 2013 @ 08:14 PM EDT


 Forum Index > Support > Plugin Support New Topic Post Reply
 Add JavaScript before the closing body tag
   
::Ben
 10/03/09 11:48AM (Read 3135 times)  
+++++
Full Member

Status: offline


Registered: 01/14/05
Posts: 1359
Hello,

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

Thanks,

::Ben

We speak french on http://geeklog.fr
 
Profile Email Website
 Quote
suprsidr
 10/03/09 04:04PM  
+++++
Full Member

Status: offline


Registered: 12/29/04
Posts: 552

function plugin_getheadercode_pluginName()

-s

FlashYourWeb and Your Gallery with the E2 XML Media Player for Gallery2 - http://www.flashyourweb.com
 
Profile Email Website
 Quote
::Ben
 10/03/09 04:50PM  
+++++
Full Member

Status: offline


Registered: 01/14/05
Posts: 1359
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

We speak french on http://geeklog.fr
 
Profile Email Website
 Quote
suprsidr
 10/03/09 05:15PM  
+++++
Full Member

Status: offline


Registered: 12/29/04
Posts: 552
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
 
Profile Email Website
 Quote
Dirk
 10/03/09 05:27PM  
AAAAA
Admin

Status: offline


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

bye, Dirk

 
Profile Email Website
 Quote
suprsidr
 10/03/09 05:53PM  
+++++
Full Member

Status: offline


Registered: 12/29/04
Posts: 552
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
 
Profile Email Website
 Quote
jmucchiello
 10/03/09 09:32PM  
+++++
Full Member

Status: offline


Registered: 08/29/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.

 
Profile Email
 Quote
::Ben
 10/04/09 02:46AM  
+++++
Full Member

Status: offline


Registered: 01/14/05
Posts: 1359
Thanks for all these ways.

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

::Ben

We speak french on http://geeklog.fr
 
Profile Email Website
 Quote
Content generated in: 1.36 seconds
New Topic Post Reply

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